Sub topic 5
Installing AWS CLI v2
This chapter covers installing AWS CLI v2 on Linux, macOS, and Windows, and confirming that the install works. It assumes you can use a terminal, know what a PATH variable is, and have permission to install software on your machine. You do not need AWS credentials yet. Credentials and profiles come in the next chapter.
What you are installing
The AWS CLI is a single program named aws. It turns commands you type into signed API requests to AWS services. Version 2 is the current major version. It ships as a self-contained bundle with its own Python runtime, so you do not need Python installed, and it does not use your system's Python packages.
Version 1 was distributed through pip. Version 2 is not on PyPI as an official install route, so pip install awscli gives you version 1 (or an unofficial package). Use the installers described below.
Some behavior differs between the versions. Version 2 supports IAM Identity Center sign-in through aws configure sso, uses a pager for output by default, and treats binary input parameters as base64 by default. Scripts written for version 1 usually work, but check the pager and binary-parameter differences if a script changes behavior after an upgrade.
Choosing an install method
| Platform | Common method | Update method |
|---|---|---|
| Linux (x86_64 or ARM) | Official zip bundle with `install` script | Rerun the installer with `--update` |
| macOS | Official `.pkg` installer, or Homebrew | Rerun the installer, or `brew upgrade awscli` |
| Windows | Official `.msi` installer, or `winget` | Rerun the installer |
| Containers | Official Docker image `amazon/aws-cli` | Pull a newer image tag |
Package managers such as Homebrew can lag behind official releases by a few days. The official installers are the reference option. If your organization manages software centrally, use their packaging and still run the verification steps below.
Installing on Linux
Pick the zip that matches your CPU architecture. Check it first:
uname -mx86_64 means the x86 bundle. aarch64 means the ARM bundle. Download, unzip, and install:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/installFor ARM, replace x86_64 in the URL with aarch64. You need curl and unzip. Minimal containers often lack unzip, so install it from your distribution's package manager if the command is missing.
The installer places files in /usr/local/aws-cli and creates a symbolic link at /usr/local/bin/aws. That directory is normally on PATH.
If you cannot use sudo, install into your home directory:
./aws/install --install-dir "$HOME/.local/aws-cli" --bin-dir "$HOME/.local/bin"Then make sure $HOME/.local/bin is on your PATH.
To update later, rerun the same download and unzip steps and add the --update flag:
sudo ./aws/install --updateWithout --update, the installer stops with an error when an installation already exists at the target path.
Installing on macOS
Download the .pkg file from https://awscli.amazonaws.com/AWSCLIV2.pkg and open it, or install from the terminal:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /The .pkg is a universal build and works on both Intel and Apple silicon Macs. The installer links aws into /usr/local/bin. With Homebrew, brew install awscli also installs version 2.
Installing on Windows
Download and run https://awscli.amazonaws.com/AWSCLIV2.msi, or run it from a terminal:
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msiThe MSI installs to C:\Program Files\Amazon\AWSCLIV2 and adds that folder to the system PATH. Windows terminals read PATH when they start, so close and reopen any terminal that was open during the install.
Verifying the install
Run this in a new terminal session:
aws --versionA successful result starts with aws-cli/2. followed by the version, then the Python runtime, operating system, and architecture. The exact numbers depend on when you install, so do not compare them to a tutorial. What matters is that the first token begins with aws-cli/2.
If the output begins with aws-cli/1, an older version 1 install is earlier on your PATH than the new one. The next section shows how to find it.
Finding which `aws` runs
When several installs exist, the shell runs the first match on PATH. Look at all matches:
which -a awsOn Windows, use where aws instead. Common causes of a stale version are:
- A
pip install awsclifrom an earlier project, often in~/.local/binor a virtual environment. - A Homebrew copy in
/opt/homebrew/binthat shadows the/usr/local/binlink. - A shell that has cached the old location. Run
hash -rin bash, or open a new terminal.
Remove the older copy, or reorder PATH so the version 2 location comes first. If you must keep version 1 for an old project, call version 2 by its full path or put each version in a separate environment.
Other checks after installing
Three quick checks catch most remaining problems:
- Run
aws help. It should display the top-level help. If the output looks garbled or hangs, the pager is the likely cause. Version 2 sends long output through a pager such asless. SetAWS_PAGER=""in your environment, orcli_pager=in your config file, to turn it off. This also matters in scripts and CI jobs, where a pager waiting for a keypress will hang the job. - Check shell completion if you want it.
aws_completerships with the install. Enabling it is shell specific, and the AWS documentation lists the steps for bash, zsh, and PowerShell. - Confirm outbound HTTPS works. Behind a corporate proxy, set
HTTPS_PROXY, and setAWS_CA_BUNDLEif your proxy re-signs traffic with a private certificate authority.
Note that aws --version makes no network call and needs no credentials. A passing result proves only that the program is installed. It does not prove you can reach AWS or that you are signed in. You will test that in the next chapter with aws sts get-caller-identity.
Checking download integrity
The Linux zip is published with a detached signature file. You can verify it with GPG against the AWS CLI public key listed in the official documentation. Use this when your security policy requires verified downloads. The macOS .pkg can be checked with pkgutil --check-signature AWSCLIV2.pkg. Both checks protect against a corrupted or tampered download, which matters more when you install on build servers than on a personal laptop.
Updating and uninstalling
The CLI does not update itself. Check your version periodically, since newer releases add services and operations. A command that works in the documentation but fails locally with "invalid choice" often means your CLI is out of date.
To uninstall on Linux, remove the symlink and the install directory:
sudo rm /usr/local/bin/aws
sudo rm /usr/local/bin/aws_completer
sudo rm -rf /usr/local/aws-cliOn macOS, remove the same paths. On Windows, use Apps and Features. Uninstalling leaves your ~/.aws directory intact, so your configuration and credentials remain.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `command not found: aws` | Install directory is not on PATH, or the terminal predates the install | Add the directory to PATH and open a new terminal |
| `aws-cli/1.x` printed | An older copy appears earlier on PATH | Use `which -a aws`, remove or reorder |
| Installer says it found an existing installation | Existing install and no `--update` flag | Rerun with `--update` |
| `Permission denied` during install | No write access to `/usr/local` | Use `sudo`, or install with `--install-dir` and `--bin-dir` in your home directory |
| Output hangs waiting for a key | Pager is active in a script | Set `AWS_PAGER=""` |
| `aws: command not found` on ARM machine after install | The x86 bundle was installed | Reinstall using the `aarch64` bundle |
Exercise
After installing AWS CLI v2 on Linux, running aws --version prints aws-cli/1.29.0 .... What command shows where the old copy lives, and what are two ways to make version 2 the one that runs?
Show answer
Run which -a aws (or where aws on Windows) to list every aws on PATH in order. The first entry is the one that runs. To make version 2 run, either remove the older install (for example pip uninstall awscli, or remove the Homebrew copy), or put the directory holding version 2 (such as /usr/local/bin) ahead of the older one in PATH. Run hash -r or open a new terminal afterward, then rerun aws --version.
Exercise
A CI job that calls aws ec2 describe-instances hangs indefinitely on a freshly built Linux runner, although the same command works on your laptop. What is the most likely cause, and how do you fix it?
Show answer
The CLI v2 pager is waiting for input because output is long enough to open less. Set AWS_PAGER="" in the job's environment, or set cli_pager= in the config file, so output goes directly to standard output.