Linux

How to install aws cli on Linux

How to Install AWS CLI on Linux

The Amazon Web Services Command Line Interface (AWS CLI) is a powerful tool that allows users to interact with AWS services from the terminal. Whether you’re managing EC2 instances, setting up S3 buckets, or deploying applications with Elastic Beanstalk, the AWS CLI simplifies the process. In this guide, I’ll show you how to install the AWS CLI on Linux, configure it, and verify that it’s working correctly.

What is AWS CLI?
The AWS Command Line Interface (CLI) is an open-source tool that enables you to manage AWS services using commands in your terminal program. With AWS CLI, you can control multiple AWS services from the command line and automate them through scripts. This tool is especially useful for developers and system administrators who want to streamline tasks without needing to navigate the AWS Management Console.

Step 1: Update Your Linux System
Before installing any new software, it’s always good to make sure your system is up to date. Open your terminal and run the following commands:

sudo apt update && sudo apt upgrade -y # For Debian-based systems (Ubuntu, etc.)
sudo dnf update -y # For Fedora-based systems
sudo yum update -y # For Red Hat-based systems

Updating your system ensures you have the latest security patches and software versions installed, which can prevent compatibility issues during the installation process.

Step 2: Install Dependencies
The AWS CLI requires some basic dependencies to function properly. Most Linux distributions come with these pre-installed, but it’s good to check. To install the required dependencies, run:

sudo apt install unzip curl -y # For Debian-based systems
sudo dnf install unzip curl -y # For Fedora-based systems
sudo yum install unzip curl -y # For Red Hat-based systems

Step 3: Download the AWS CLI Installer
The next step is to download the AWS CLI version 2 installation file. You can do this using curl. Open your terminal and run the following command:

curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”

This will download the latest version of AWS CLI as a .zip file.

Step 4: Unzip the Installation File
Now that the file is downloaded, you need to extract it. Use the following command:

unzip awscliv2.zip

If you encounter an error, ensure that unzip is installed on your system (refer to the previous section to install it).

Step 5: Install the AWS CLI
To install AWS CLI, navigate to the directory where you unzipped the installer and run:

sudo ./aws/install

If the installation is successful, you should see a confirmation message. The installation script installs the aws command to /usr/local/bin/aws and creates necessary directories.

Step 6: Verify the Installation
To confirm that AWS CLI has been installed correctly, use the following command:

aws –version

You should see output similar to:

aws-cli/2.0.30 Python/3.8.8 Linux/4.15.0-112-generic exe/x86_64

If you see this or a similar output, congratulations! You’ve successfully installed the AWS CLI.

Step 7: Configure AWS CLI
Before you can start using the AWS CLI, you need to configure it with your AWS credentials. Run:

aws configure

You’ll be prompted to enter:

AWS Access Key ID – Your access key ID.
AWS Secret Access Key – Your secret access key.
Default Region Name – The default region to use, e.g., us-west-2.
Default Output Format – The output format, e.g., json, yaml, text, or table.
Example:

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

You can obtain the Access Key ID and Secret Access Key from the AWS Management Console. Make sure to store these securely.

Step 8: Test AWS CLI Commands
Now that the AWS CLI is installed and configured, you can start testing some commands. For example, to list all S3 buckets, you can run:

aws s3 ls

You can also check your configured account details:

aws sts get-caller-identity

These commands will confirm that your AWS CLI is properly configured and working as expected.

Upgrading AWS CLI
To update your AWS CLI to the latest version, you need to re-download the installer and run the installation commands again. You can use the following command:

curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip” && unzip awscliv2.zip && sudo ./aws/install –update

This will automatically upgrade your existing AWS CLI to the latest version.

Uninstalling AWS CLI
If for any reason you need to uninstall AWS CLI, you can use:

sudo /usr/local/bin/aws/uninstall

This command will remove AWS CLI from your system.

Conclusion
Installing the AWS CLI on Linux is a straightforward process, but ensuring it’s configured correctly is crucial for managing AWS services effectively. By following this guide, you’ve learned how to install, configure, and test the AWS CLI on a Linux machine. With this tool, you can perform a wide range of tasks, automate processes, and manage your AWS infrastructure efficiently from the command line. For more information on AWS CLI commands and usage, you can visit the official AWS CLI documentation.

FAQs

  • 1. Can I use AWS CLI on any Linux distribution?
    Yes, AWS CLI can be installed on most Linux distributions including Ubuntu, Debian, Fedora, and Red Hat. Just ensure you follow the appropriate commands for your distribution.
  • 2. Is there a way to install AWS CLI without using the terminal?
    Yes, you can download the binary installer from the AWS website, but using the terminal is generally quicker and easier for most Linux users.
  • 3. Can I manage multiple AWS accounts with AWS CLI?
    Yes, you can configure multiple profiles in the ~/.aws/config file, which allows you to switch between different AWS accounts.

Final Tips

  • Always keep your AWS CLI updated to benefit from new features and security improvements.
  • Ensure your AWS credentials are securely stored and do not share them publicly.
  • Explore AWS CLI documentation to learn about more advanced features and commands.
  • By following these steps, you should be able to confidently install and configure AWS CLI on your Linux
  • system, paving the way for streamlined AWS management.

AWS CLI Official Website

Thank you for visiting our website! If you want to enhance your skills with Linux systems and would like to read our article on “How to Install Google Cloud CLI (Command-Line Interface) on Mac, Windows, and Linux,” you can find it through the link below. Happy learning! 🙂

How to Install Google Cloud CLI (Command-Line Interface) on Mac, Windows, and Linux

 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button