How to Install AWS CLI on Ubuntu 26.04, 24.04, and 22.04

Cloud automation becomes painful when every S3 sync, IAM check, or EC2 lookup requires a trip through the AWS Console. The AWS Command Line Interface (AWS CLI) lets you run all of those operations directly from your terminal. This guide covers four installation methods for Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS, then walks through configuration, common commands, updates, troubleshooting, and removal.

Install AWS CLI on Ubuntu
Install AWS CLI on Ubuntu

Use the AWS official installer for AWS CLI v2 on any of the three supported releases. Snap is also AWS-published and handles automatic updates. The pip method covers legacy AWS CLI v1 inside a Python virtual environment. The Ubuntu package option applies only where its release-specific candidate fits your workflow.

Choose Your Installation Method

MethodVersionRelease CoverageUpdatesBest For
AWS official installerAWS CLI v2Ubuntu 26.04, 24.04, 22.04Rerun installer with --updateMost users, servers, CI/CD, production
Snap packageAWS CLI v2 (v2/stable)Ubuntu systems with snapdAutomatic Snap refreshUsers who want AWS-published auto-updates
pip virtual environmentAWS CLI v1Ubuntu 26.04, 24.04, 22.04 after python3-venvUpgrade inside the virtual environmentLegacy scripts that require v1
Ubuntu awscli packageRelease-dependentAvailable on 26.04 and 22.04; no candidate on 24.04APT upgradesOnly where the Ubuntu package version fits

Pick one method. Every method places an aws command on your PATH, so mixing methods causes update and troubleshooting confusion.

Check the Ubuntu awscli Package First

Many users search for apt install awscli, but the available package differs by Ubuntu release. The table below shows what APT offers by default:

Ubuntu ReleaseDefault awscli CandidateGuidance
Ubuntu 26.04 LTS2.31.x from universeWorks as an Ubuntu-packaged v2 option, but the AWS installer and Snap track AWS’s current v2 release more directly
Ubuntu 24.04 LTSNo package candidateUse the AWS installer, Snap, or pip v1 virtual environment
Ubuntu 22.04 LTS1.22.x from universeProvides old AWS CLI v1. Use the AWS installer or Snap if you need v2

If you deliberately choose the Ubuntu package on a supported release, install it with APT:

sudo apt install awscli

On minimal systems, the universe component may not be enabled. If APT cannot locate awscli or python3-venv, enable universe first:

sudo apt install software-properties-common -y
sudo add-apt-repository universe
sudo apt update

Method 1: Install AWS CLI on Ubuntu with the Official Installer

The official installer downloads AWS CLI v2 as a bundled Linux build. It does not depend on Ubuntu’s system Python version, so the same command sequence works across all three supported Ubuntu LTS releases.

Step 1: Refresh APT metadata and install the required tools:

sudo apt update
sudo apt install curl unzip -y

Step 2: Download the current x86_64 installer archive:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" \
  -o "awscliv2.zip"

ARM64 systems: Replace the URL above with https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip and download the matching .sig file instead.

Step 3: Extract the archive and install AWS CLI:

unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli

Step 4: Clean up the installer files:

rm -rf awscliv2.zip aws/

Step 5: Confirm the installation:

aws --version

Expected output:

aws-cli/2.x.x Python/3.x.x Linux/7.0.0-14-generic exe/x86_64.ubuntu.26

The exe/ segment confirms you are running the bundled AWS CLI v2 build from the official installer.

Method 2: Install AWS CLI v2 with Snap

Amazon Web Services publishes the AWS CLI directly on Snapcraft with classic confinement. Standard Ubuntu desktop and server installs include snapd by default. If snap is missing on a minimal system, install it first:

sudo apt install snapd -y

Install the v2/stable channel explicitly:

sudo snap install aws-cli --channel=v2/stable --classic

Important: Always specify --channel=v2/stable. The latest/stable and v1/stable channels can install AWS CLI v1 on some systems, which is the wrong major version for most workflows.

Verify the Snap path and version:

command -v aws
aws --version
/snap/bin/aws
aws-cli/2.x.x Python/3.x.x Linux/7.0.0-14-generic exe/x86_64.ubuntu.26

If you need AWS CLI v1 from Snap for legacy compatibility, install the v1 channel:

sudo snap install aws-cli --channel=v1/stable --classic

To switch channels on an existing Snap install:

sudo snap refresh aws-cli --channel=v1/stable

Method 3: Install AWS CLI v1 in a Python Virtual Environment

The pip package installs AWS CLI v1, not AWS CLI v2. Use this method only for legacy scripts or environments that still require v1 command behavior. A Python virtual environment avoids Ubuntu’s externally managed system Python restrictions on 24.04 and newer releases.

Do not confuse the official awscli package on PyPI with the third-party awscliv2 wrapper. AWS publishes v2 through the official installer and Snap only.

Step 1: Install the virtual environment support package:

sudo apt install python3-venv -y

Step 2: Create and activate a dedicated virtual environment:

python3 -m venv ~/.aws-cli-v1
source ~/.aws-cli-v1/bin/activate

Step 3: Install AWS CLI v1 inside the environment:

pip install awscli

Step 4: Verify the binary directly:

~/.aws-cli-v1/bin/aws --version
aws-cli/1.x.x Python/3.x.x Linux/7.0.0-14-generic botocore/1.x.x

Step 5 (Optional): Add the virtual environment to your shell PATH so the v1 command runs without activating the environment each time. The guard prevents duplicate PATH entries if you rerun it:

touch ~/.bashrc
grep -qxF 'export PATH="$HOME/.aws-cli-v1/bin:$PATH"' ~/.bashrc || \
  echo 'export PATH="$HOME/.aws-cli-v1/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Configure AWS CLI on Ubuntu

AWS CLI needs credentials and a default region before it can call AWS services. Access key data stores in ~/.aws/credentials, while region and output settings store in ~/.aws/config.

Configure with Access Keys

Start the interactive configuration wizard:

aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json

Replace the example values with your real access key, secret key, default region, and preferred output format. Valid output formats are json, yaml, yaml-stream, text, and table.

Keep credentials out of shell history, Git repositories, screenshots, and shared terminal transcripts.

Configure with IAM Identity Center

If your organization uses AWS IAM Identity Center, configure SSO instead of long-lived access keys:

aws configure sso

After the profile exists, authenticate with:

aws sso login --profile production

Replace production with the profile name you created during setup.

Verify Your Configuration

List your active configuration values:

aws configure list
NAME        VALUE                   TYPE        LOCATION
profile     <not set>               None        None
access_key  <not set>               None        None
secret_key  <not set>               None        None
region      <not set>               None        None

Values of <not set> mean the current profile is incomplete. After credentials are configured, test the active identity:

aws sts get-caller-identity
{
    "UserId": "AIDACKCEVSQ6C2EXAMPLE",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:user/username"
}

This command confirms that AWS CLI can sign requests and reach AWS with the active credentials.

Create Multiple Profiles

Use named profiles when you work with multiple AWS accounts, roles, or regions:

aws configure --profile production

Run commands against a specific profile with --profile:

aws sts get-caller-identity --profile production

To set a default profile for all commands in the current shell session:

export AWS_PROFILE=production

Use AWS CLI on Ubuntu

After installation and configuration, AWS CLI commands work the same way across the official installer, Snap, pip v1, and Ubuntu package methods.

List S3 Buckets

aws s3 ls

With valid credentials, this prints bucket names. No output means the account has no visible buckets.

Copy and Sync Files to S3

aws s3 cp localfile.txt s3://bucket-name/
aws s3 sync ./local-directory s3://bucket-name/remote-directory

The sync command uploads changed files only, which makes it useful for backup scripts and static-site deployment workflows.

Inspect EC2 Instances

aws ec2 describe-instances
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --output table

The first command returns detailed JSON. The second limits results to running instances and formats the output as a table.

Manage IAM Users

aws iam list-users
aws iam create-user --user-name new-user
aws iam attach-user-policy --user-name new-user --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess

Use real user names and policy ARNs for your account.

Update AWS CLI on Ubuntu

Update AWS CLI with the same manager you used for installation. Confirm the active binary first with command -v aws.

Update the Official Installer Method

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
rm -rf awscliv2.zip aws/
aws --version

If no newer version is available, the installer prints:

Found same AWS CLI version: /usr/local/aws-cli/v2/2.x.x. Skipping install.

Update the Snap Method

sudo snap refresh aws-cli
aws --version

Snap also refreshes packages automatically in the background, so the manual refresh is mainly useful when you want to check immediately.

Update the pip v1 Method

~/.aws-cli-v1/bin/pip install --upgrade awscli
~/.aws-cli-v1/bin/aws --version

Troubleshoot AWS CLI on Ubuntu

Fix: aws Command Not Found

Check which aws binary your shell can find:

command -v aws

For the official installer, confirm the symlink points to the current AWS CLI v2 directory:

ls -l /usr/local/bin/aws
lrwxrwxrwx 1 root root 37 Apr 28 19:00 /usr/local/bin/aws -> /usr/local/aws-cli/v2/current/bin/aws

If the symlink is missing, rerun the official installer with the same --bin-dir and --install-dir paths.

or Snap installs, open a new login shell if /snap/bin/aws is not on your PATH. For pip v1 installs, run ~/.aws-cli-v1/bin/aws --version directly, or add the virtual environment path as shown in the installation steps above.

Fix: python3 venv ensurepip Error

If python3 -m venv reports that ensurepip is unavailable, install the venv package and recreate the environment:

sudo apt install python3-venv -y
rm -rf ~/.aws-cli-v1
python3 -m venv ~/.aws-cli-v1

Fix: Unable to Locate Package awscli

On Ubuntu 24.04, awscli has no default APT candidate, so sudo apt install awscli fails even when repositories are healthy:

Package awscli is not available, but is referred to by another package.
E: Package 'awscli' has no installation candidate

Use the official installer or Snap for AWS CLI v2 on Ubuntu 24.04.

On Ubuntu 26.04 and 22.04, the package comes from universe. If APT cannot locate awscli or python3-venv, enable the universe repository and refresh:

sudo apt install software-properties-common -y
sudo add-apt-repository universe
sudo apt update

Fix: Unable to Locate Credentials

AWS CLI prints this error when the active profile has no usable credentials:

aws: [ERROR]: An error occurred (NoCredentials): Unable to locate credentials.
You can configure credentials by running "aws login".

Run aws configure for access keys, or use aws configure sso and aws sso login for IAM Identity Center profiles. Then rerun aws sts get-caller-identity to confirm the profile works.

Fix: SSL Certificate Errors

Certificate failures usually point to missing CA certificates or an incorrect system clock. Refresh the CA package first:

sudo apt install ca-certificates -y
sudo update-ca-certificates

Then check time synchronization:

timedatectl status
sudo timedatectl set-ntp true

Remove AWS CLI from Ubuntu

AWS CLI credentials and profiles live under ~/.aws/ and are not removed by package, Snap, or installer cleanup unless you delete them separately.

Remove the Official Installer

sudo rm -f /usr/local/bin/aws /usr/local/bin/aws_completer
sudo rm -rf /usr/local/aws-cli
hash -r
command -v aws || echo "aws removed"

Remove the Snap Package

sudo snap remove --purge aws-cli
hash -r
command -v aws || echo "aws removed"

Remove the pip v1 Virtual Environment

rm -rf ~/.aws-cli-v1

If you added the PATH line earlier, remove it from ~/.bashrc:

path_line='export PATH="$HOME/.aws-cli-v1/bin:$PATH"'
grep -vxF "$path_line" ~/.bashrc > ~/.bashrc.tmp
mv ~/.bashrc.tmp ~/.bashrc
source ~/.bashrc

Remove the Ubuntu Package

sudo apt remove awscli
sudo apt autoremove --dry-run

Review the dry-run output before confirming removals.

Remove AWS CLI Configuration Files

Back up ~/.aws/ before deleting it, because it holds saved profiles, regions, SSO settings, and credentials:

if [ -d ~/.aws ]; then
    cp -r ~/.aws ~/.aws-backup
fi
rm -rf ~/.aws

Keep the backup until you confirm you no longer need those profiles.

Related Tech Guides

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply