TerraformPilot

DevOps

Install AWS CLI on Ubuntu: Step-by-Step Guide

Install AWS CLI v2 on Ubuntu 22.04 and 24.04 using the official installer, snap, or pip. Configure credentials, test with Terraform, and set up autocomplete.

LLuca Berton1 min read

The AWS CLI is required for many Terraform workflows — configuring credentials, debugging, and managing state backends. Here's how to install AWS CLI v2 on Ubuntu.

#
# Download
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
 
# Install unzip if needed
sudo apt-get update && sudo apt-get install -y unzip
 
# Extract and install
unzip awscliv2.zip
sudo ./aws/install
 
# Verify
aws --version
# aws-cli/2.17.x Python/3.12.x Linux/6.x.x
 
# Clean up
rm -rf awscliv2.zip aws/

ARM64 (Graviton, Raspberry Pi)

#
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Method 2: Snap

#
sudo snap install aws-cli --classic
aws --version

Simple, auto-updates. Slightly slower startup than the native binary.

Method 3: pip

#
# Not recommended — can conflict with system packages
pip3 install awscli

Use this only in virtual environments or containers.

⚠️ Don't Use apt install awscli

#
# ❌ This installs AWS CLI v1 (outdated)
sudo apt install awscli
aws --version
# aws-cli/1.x.x — OLD, missing v2 features

Ubuntu's default awscli package is v1. Always use the official installer for v2.

Configure Credentials

#

Interactive Setup

#
aws configure
# AWS Access Key ID [None]: AKIA...
# AWS Secret Access Key [None]: ****
# Default region name [None]: us-east-1
# Default output format [None]: json

Creates ~/.aws/credentials and ~/.aws/config.

Named Profiles

#
aws configure --profile production
# AWS Access Key ID: AKIA...
# ...
 
# Use with Terraform
export AWS_PROFILE=production
terraform plan
#
aws configure sso
# SSO session name: my-org
# SSO start URL: https://my-org.awsapps.com/start
# SSO Region: us-east-1
 
# Login
aws sso login --profile my-org
 
# Use with Terraform
export AWS_PROFILE=my-org
terraform plan

Enable Autocomplete

#
# Bash
echo 'complete -C aws_completer aws' >> ~/.bashrc
source ~/.bashrc
 
# Zsh
echo 'autoload -U +X bashcompinit && bashcompinit' >> ~/.zshrc
echo 'complete -C aws_completer aws' >> ~/.zshrc
source ~/.zshrc

Verify with Terraform

#
# Check AWS identity
aws sts get-caller-identity
# {
#     "UserId": "AIDA...",
#     "Account": "123456789012",
#     "Arn": "arn:aws:iam::123456789012:user/myuser"
# }
 
# Terraform uses the same credentials
terraform init
terraform plan

Update AWS CLI

#
# Official installer — re-run with --update
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --update
rm -rf awscliv2.zip aws/
 
# Snap
sudo snap refresh aws-cli

Docker

#
FROM ubuntu:24.04
 
RUN apt-get update && \
    apt-get install -y curl unzip && \
    curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
    unzip awscliv2.zip && \
    ./aws/install && \
    rm -rf awscliv2.zip aws/ && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

Troubleshooting

#

"aws: command not found" After Install

#
# Check install location
which aws
ls -la /usr/local/bin/aws
 
# If not in PATH
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

"Unable to locate credentials"

#
# Check for credentials
aws configure list
# If all "not set" — run aws configure
 
# Check environment variables
env | grep AWS_

SSL Certificate Errors

#
sudo apt-get install -y ca-certificates

Hands-On Courses

#

Conclusion

#

Use the official AWS installer for CLI v2 on Ubuntu — it's always current and doesn't conflict with system packages. Avoid apt install awscli (it's v1). Configure credentials with aws configure or SSO for organizations. Terraform automatically uses the same ~/.aws/credentials that the CLI uses.

#AWS#DevOps#Installation#Ubuntu#CLI

Share this article