How to Install AWS CLI on Ubuntu[3 Proven Methods]

Written by

Reviewed by

Last updated: June 13, 2024

Expert verified

SVG Image

TL;DR

To install AWS CLI on Ubuntu, you can follow these steps:

  1. Open a Terminal window. Check your Ubuntu version with lsb_release -a.
  2. Update your package list using sudo apt update.
  3. Install Python by running sudo apt install python3.
  4. Verify the Python installation with python3 --version.
  5. Install Pip with sudo apt install python3-pip.
  6. Confirm Pip installation using pip3 --version.
  7. Install AWS CLI by running pip3 install awscli --upgrade --user.
  8. Verify the AWS CLI installation with aws --version.

Explore the step-by-step method to install AWS CLI on Ubuntu in the guide below. Also, learn about the common errors that can occur during installation.

Installing AWS CLI on Ubuntu can seem daunting, but it doesn’t have to be. If you’re looking to manage your AWS resources efficiently from the command line, you’ve come to the right place. In this guide, I’ll show you step-by-step how to install AWS CLI using APT, PIP, and manual methods. You’ll also learn how to configure it with your credentials and apply crucial security practices to protect your data. Let’s make the installation process smooth and straightforward so you can start leveraging the power of AWS CLI.

What is AWS CLI?

AWS CLI, or Amazon Web Services Command Line Interface, is a tool that lets you interact with AWS services directly from your command line. Instead of using the AWS Management Console (the web-based interface), you can type commands to manage your AWS resources. This tool is useful for tasks like launching servers, managing storage, and deploying applications.

Benefits of Using AWS CLI

  • Efficiency: AWS CLI allows you to perform tasks quickly by typing commands instead of navigating through the web interface. This can save a lot of time, especially for repetitive tasks.
  • Automation: You can write scripts that use AWS CLI commands to automate tasks. For example, you could create a script to back up your data every night. This reduces the chance of human error and ensures consistency.
  • Control: AWS CLI gives you complete control over your AWS services. You can specify every detail of your commands, which is great for advanced users who need precise configurations.
  • Flexibility: You can use AWS CLI on different operating systems like Linux, macOS, and Windows. This means you can work in your preferred environment without any limitations.
  • Cost Management: By using AWS CLI, you can easily monitor and manage your AWS resources. For example, you can write commands to check your usage and optimize your spending.
  • Integration: AWS CLI works well with other tools and services. You can integrate it with DevOps tools like Jenkins or Terraform to streamline your development and deployment processes.

How to Install AWS CLI on Ubuntu

To install AWS CLI on Ubuntu, first open a Terminal window. Check your Ubuntu version with lsb_release -a, then update your package list using sudo apt update. Install Python by running sudo apt install python3 and verify it with python3 --version. Next, install Pip with sudo apt install python3-pip and confirm it using pip3 --version. Finally, install AWS CLI by running pip3 install awscli --upgrade --user and verify the installation with aws --version.

Here is the detailed step-by-step guide for three different methods to install AWS CLI on Ubuntu:

1. Install AWS CLI Using PIP

  1. Open a Terminal window.
opening terminal 27
  1. Enter the following command to check your Ubuntu version:
lsb_release -a
  1. This command will display your Ubuntu version.
checking ubuntu version
  1. Update the package list by opening a Terminal and running the command:
sudo apt update
  1. This command will refresh the package list to ensure you have the latest versions available.
updating system package list 12
  1. Install Python by executing the following command:
sudo apt install python3
  1. This command will install Python, a programming language required for AWS CLI.
installing python on ubuntu
  1. Verify the Python installation by checking the version:
python3 --version
  1. This command will display the installed Python version.
checking python version
  1. Install Pip, the package installer for Python, using the command:
sudo apt install python3-pip
  1. This command will install Pip, which is necessary for managing Python packages.
installing pip on ubuntu
  1. Verify the Pip installation by checking the version:
pip3 --version
  1. This command will display the installed Pip version.
checking pip version
  1. Now you can install AWS CLI using Python and Pip, by running the following command to install AWS CLI using Pip:
pip3 install awscli --upgrade --user
  1. This command will install AWS CLI on your Ubuntu system, specifically for the current user.
installing awscli on ubuntu
  1. To ensure that AWS CLI is installed correctly, you can check the version by running the following command in the Terminal:
aws --version
  1. The command will display the installed AWS CLI version.
viewing installed version of awscli

2. Installing AWS CLI via APT

The Advanced Package Tool (APT) is Ubuntu’s default package manager, which makes it easy to install, update, and manage software packages.

  1. Before installing any new software, it’s important to update your system to ensure all existing packages are up to date.
sudo apt update && sudo apt upgrade -y

This command updates the package list and upgrades all existing packages to their latest versions.

updating and upgrading packages
  1. Install the AWS CLI package using APT.
sudo apt install awscli -y

This command downloads and installs the AWS CLI package along with any necessary dependencies.

installing aws cli on ubuntu using apt
  1. After installation, it’s crucial to verify that AWS CLI is installed correctly.
aws --version

This command will display the version of AWS CLI installed, confirming a successful installation.

verifying aws cli installation

3. Manual Installation of AWS CLI

Manual installation of AWS CLI provides more control over the installation process, allowing users to install the latest version directly from AWS. This method is useful if you prefer not to use the package manager or if you need a specific version of AWS CLI that isn’t available in the APT repository.

  1. Downloading the AWS CLI bundle ensures that you are getting the latest version directly from AWS.
  2. Use the curl command to download the AWS CLI bundle from the official AWS website.
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

This command fetches the AWS CLI bundle and saves it as awscliv2.zip.

downloading aws bundle using curl
  1. After downloading, extract the contents of the zip file.
unzip awscliv2.zip

This command unzips the file, creating a directory containing the installation files.

extracting content of downloaded zip file
  1. Navigate to the extracted directory and run the installation script.
sudo ./aws/install

This command initiates the installation process. The sudo prefix ensures that the installation has the necessary permissions.

initiating the installation process
  1. Once the installation is complete, verify that AWS CLI is installed correctly.
aws --version

This command displays the installed version of AWS CLI, confirming a successful installation.

verifying aws cli installation through bundle

How to Configure AWS CLI

After successfully installing AWS Command Line Interface (CLI), the next crucial step is to AWS configure Ubuntu with your AWS access credentials. Configuring AWS CLI allows you to authenticate and interact with your AWS resources seamlessly. To authenticate with AWS CLI, you’ll need an AWS access key and secret access key. If you don’t have these credentials, follow these steps to generate them:

  1. Go to the AWS Management Console. Select Identity and Access Management (IAM) service, provide your registered ID, and then cleck on Next button. You can also create a new account by providing the credentials. 
loging to aws management console
  1. Entering credentials to sign in.
entering credentials to signin
  1. Now open the security credentials by clicking on the username on the top right corner of AWS Management Console.
opening security credentials
  1. Navigate to the Users section in the IAM dashboard.
opening users tab from IAM dashboard
  1.  Select the user to which you want to create the access key.
choosing user to create access key
  1. Go to the security credentials tab of the user.
choosing security credentials tab of user
  1. Under the Security credentials tab, click Create access key.
navigating to access key section
  1. Now choose the use case for which you want to create the access key. In this case, I am selecting the command line interface.
choosing usecase for access key
  1. Now accept terms and conditions and click on the Next button to proceed further.
accepting terms and conditions
  1. Click on Create Access Key button to generate access key.
generating access key for awscli
  1. Take note of the generated access key ID and secret access key.
save or download access key
  1. Configuring AWS CLI with Access Keys: Configure AWS CLI by running the following command in the Terminal:
aws configure
  1. You will be prompted to enter your AWS access key ID, secret access key, default region, and output format. Provide the required information accordingly.

Security Best Practices for AWS CLI

When using AWS CLI, it’s important to follow security best practices to protect your data and resources. These guidelines help you manage your AWS environment securely and reduce the risk of unauthorized access or data breaches. Here are five key practices to keep in mind:

  • 🔒 Use IAM Roles Instead of Access Keys: Assign IAM roles to your instances instead of using access keys. This approach provides temporary credentials, reducing the risk of exposure and improving security management.
  • 🔑 Regularly Rotate Access Keys: Change your access keys frequently to minimize the risk of compromised credentials. AWS recommends rotating access keys every 90 days and immediately disabling old keys.
  • 🗂️ Limit Permissions with IAM Policies: Apply the principle of least privilege by granting only the permissions necessary for users to perform their tasks. This limits potential damage from compromised accounts.
  • 🛡️ Enable Multi-Factor Authentication (MFA): Require MFA for all IAM users. This adds an extra layer of security, making it harder for attackers to gain access even if they have your password.
  • 🧩 Store Secrets Securely: Use AWS Secrets Manager or AWS Systems Manager Parameter Store to manage and store secrets, such as database passwords or API keys. This keeps sensitive information secure and accessible only to authorized users.

AWS CLI Ubuntu: In a Nutshell

In this article, I’ve covered how to install AWS CLI on Ubuntu using three different methods: via APT, using PIP, and through manual installation. I have walked through each step to ensure a smooth installation process. Additionally, I have discussed how to configure AWS CLI with your credentials and shared important security best practices to protect your data and AWS resources effectively.

To continue expanding your knowledge:

  • Learn different methods to shut down an Ubuntu server, helping you manage your server environment efficiently.
  • Discover how to check the version of a Python package, ensuring compatibility and troubleshooting dependencies effectively.
  • Understand how to fix the “you have held broken packages” error on Linux, preventing installation issues and maintaining system stability.

Frequently Asked Questions

Can AWS CLI be used offline or in restricted network environments?

Yes, AWS CLI can be used offline or in restricted network environments. While some AWS CLI commands require network connectivity to interact with AWS services, many commands can be executed offline or in environments with limited internet access. AWS CLI supports offline functionality by caching information locally, allowing you to perform various tasks without a constant internet connection. This makes AWS CLI a versatile tool that can adapt to different network environments, providing flexibility and convenience in managing AWS resources.

Is it possible to use AWS CLI with multiple AWS accounts?

Yes, AWS CLI allows you to configure and switch between multiple AWS accounts using profiles. Profiles enable you to store and manage different sets of AWS access keys and settings for various accounts within the AWS CLI configuration. By using the aws configure command, you can create and manage profiles, associating each profile with a specific AWS account. This allows you to seamlessly switch between different accounts and access their respective AWS resources using AWS CLI, providing a convenient way to manage multiple AWS environments from a single command-line interface.

Are there any graphical user interfaces (GUIs) available for AWS CLI?

While AWS CLI primarily operates through the command line, there are third-party tools and IDE integrations available that provide graphical interfaces for AWS CLI commands. These GUIs aim to simplify the execution of AWS CLI commands by providing a visual representation of the commands and their parameters. They often offer features such as command autocompletion, syntax highlighting, and intuitive navigation, making it easier to interact with AWS services. Popular examples of AWS CLI GUIs include AWS Toolkit for Visual Studio Code, AWS Management Console, and various cloud management platforms that offer graphical interfaces for AWS CLI commands.

Can I use AWS CLI without providing access keys every time?

Yes, you can configure AWS CLI with access keys and other configuration settings using the aws configure command. Once you have configured AWS CLI with your access keys, it will use the specified access keys by default for subsequent commands, eliminating the need to provide them every time. Additionally, AWS CLI allows you to set a default profile, which automatically selects the appropriate access keys and configuration settings based on the chosen profile. This streamlines the usage of AWS CLI, making it more convenient and efficient for managing AWS resources without the hassle of repeatedly entering access keys.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Install Metasploit in Kali Linux [Tutorial]

Next Post

How to Remove a File from Git Repo [3 Effective Methods]

Leave a Reply

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

Read next