Sub topic 5
Installing AWS CLI v2
This chapter assumes you can use a terminal, can download and unzip files, and have permission to install software on your machine. You don't need AWS credentials yet. The next chapter covers those.
What you are installing
The AWS CLI is a program named aws. It turns commands you type into calls to AWS service APIs. Version 2 is the current major version. It ships as a self-contained installer with its own bundled Python runtime, so you don't need to install Python separately. It also adds features that version 1 lacks, such as IAM Identity Center sign-in and an interactive wizard for aws configure sso.
Version 1 and version 2 both use the command name aws. If both are installed, one hides the other, which causes confusing behavior. A later section shows how to detect this.
Install on your platform
Pick the section for your operating system.
Linux (x86_64)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/installFor an ARM machine, use awscli-exe-linux-aarch64.zip in the URL. The installer puts files in /usr/local/aws-cli and creates a symbolic link at /usr/local/bin/aws.
macOS
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /Windows
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msiRun this in Command Prompt or PowerShell. You can also download the MSI file and double-click it.
Verify the installation
Open a new terminal window so your shell reloads its PATH, then run:
aws --versionThe output looks similar to this. Your version numbers and platform will differ.
aws-cli/2.15.30 Python/3.11.8 Linux/6.5.0 exe/x86_64.ubuntu.22The line must start with aws-cli/2. If it starts with aws-cli/1, an older version is the one your shell finds first.
How the shell finds `aws`
When you type aws, your shell searches each directory in the PATH environment variable, in order, and runs the first match. The diagram shows the check you can follow when the result is not what you expect.
Common problems
command not found: The install directory is not inPATH. On Linux and macOS, confirm that/usr/local/binis inPATHand that the symbolic link exists. Open a new terminal after installing.- Version 1 appears: List every match with
which -a awson Linux and macOS, orwhere awson Windows. Remove the old copy, or put the v2 directory earlier inPATH. Shells also cache command locations, so runhash -rin bash after changes. - Permission denied during install: The default location needs administrator rights. Use
sudo, or install to a directory you own with./aws/install -i ~/aws-cli -b ~/bin.
Updating and removing
To update on Linux, download the new zip and run the installer again with the update flag:
sudo ./aws/install --updateOn macOS and Windows, run the newer installer. To uninstall on Linux, delete the symbolic link and the install directory, which are /usr/local/bin/aws and /usr/local/aws-cli by default.
Exercise
You installed AWS CLI v2, but aws --version prints aws-cli/1.22.0. Which command helps you find the cause, and what does it show?
Show answer
Run which -a aws (or where aws on Windows). It lists every aws executable on your PATH in search order. The v1 copy appears before the v2 copy, so the shell runs it first. Remove the old copy or move the v2 directory earlier in PATH.