MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

AWS Tutorials: Install and Configure AWS CLI

This guide covers installing AWS CLI version 2 on CentOS/RHEL, Ubuntu, other Linux distributions, macOS and Windows, then setting up credentials and checking that the CLI is talking to the right AWS account. The commands in the original post are completed and corrected below, and the sections after them cover profiles, SSO sign-in, updates and the errors people run into most often.

Install AWS CLi in CENTOS/RHEL

$ sudo yum remove awscli

Install AWS CLi in Ubuntu

$ sudo apt-get install awscli

Code language: JavaScript (javascript)

Install AWS CLi in Linux using Package


curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
which aws
ls -l /usr/local/bin/aws
aws --versionCode language: JavaScript (javascript)

Install AWS CLi in Windows


DOWNLOAD - https://awscli.amazonaws.com/AWSCLIV2.msi

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi /qn
aws --version
Code language: JavaScript (javascript)

Configure AWS and Verify Login


$ aws configure
AWS Access Key ID [None]: your-access-key-id
AWS Secret Access Key [None]: your-secret-access-key
Default region name [None]: region-to-use (e.g us-west-2, us-west-1, etc).
Default output format [None]:

$ aws s3 lsCode language: PHP (php)

Corrections to the commands above

The commands above get you most of the way, but a few of them are mislabelled or out of date. The table lists each problem and the fix.

OriginalProblemUse instead
sudo yum remove awscli under "Install on CentOS/RHEL"This command removes the old AWS CLI v1 package. It doesn't install anything.Remove v1 first if it's there, then use the official v2 installer (see the next section).
sudo apt-get install awscli on UbuntuOn older releases this installs AWS CLI v1, which is outdated. On newer releases such as Ubuntu 24.04 the package may not exist at all.Use the official v2 installer, or sudo snap install aws-cli --classic.
Running sudo ./aws/install and then sudo ./aws/install ... --updateThe second command is only for upgrading an existing install. Running both straight after each other does the same job twice.Use sudo ./aws/install for a new install. Use sudo ./aws/install --update when upgrading.
x86_64 download URL onlyThe x86_64 package won't run on ARM machines such as Graviton.On ARM, use awscli-exe-linux-aarch64.zip.
Checking access with aws s3 lsNeeds the s3:ListAllMyBuckets permission and prints nothing if the account has no buckets, so it doesn't prove much either way.Use aws sts get-caller-identity, which needs no special permissions.

Note: The headings above say "AWS CLi". The correct name is AWS CLI (Command Line Interface).

Install AWS CLI v2 on Linux (RHEL, CentOS, Ubuntu, Debian)

The bundled installer from AWS works on any glibc-based Linux distribution and always gives you the current v2 release. You need curl and unzip. Remove any v1 package first so that two versions don't end up competing on your PATH.

# RHEL / CentOS / Rocky / Alma: remove v1, install prerequisites
sudo yum remove -y awscli
sudo yum install -y curl unzip

# Ubuntu / Debian: remove v1, install prerequisites
sudo apt-get remove -y awscli
sudo apt-get update && sudo apt-get install -y curl unzip

# Pick the package that matches your CPU architecture
ARCH=$(uname -m)   # x86_64 or aarch64
curl "https://awscli.amazonaws.com/awscli-exe-linux-${ARCH}.zip" -o awscliv2.zip
unzip -q awscliv2.zip
sudo ./aws/install

# Verify
hash -r
which aws
aws --versionCode language: PHP (php)

By default the installer puts the files in /usr/local/aws-cli and creates a symlink at /usr/local/bin/aws. hash -r clears the shell's cache of command locations, so the shell doesn't keep running an old aws it found earlier. The version output looks something like this (your version numbers will be different):

aws-cli/2.x.x Python/3.x.x Linux/6.x.x exe/x86_64.ubuntu.24

Note: Amazon Linux 2023 comes with AWS CLI v2 already installed. Amazon Linux 2 comes with v1. Run aws --version before installing anything.

Install on macOS and Windows

On macOS, use the official package installer. It works on both Intel and Apple silicon Macs:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o AWSCLIV2.pkg
sudo installer -pkg AWSCLIV2.pkg -target /
aws --versionCode language: JavaScript (javascript)

On Windows, the msiexec commands above work as written. /qn runs the install silently with no prompts, which suits scripts and image builds. Run it from an elevated (administrator) prompt. Once it finishes, open a new terminal so the updated PATH takes effect, then check the version:

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi /qn
# open a new PowerShell window, then:
aws --versionCode language: PHP (php)

What aws configure writes, and how profiles work

aws configure saves your answers in two plain-text files in your home directory. If you leave the output format blank, the CLI uses json. Other valid formats are yaml, text and table.

# ~/.aws/credentials
[default]
aws_access_key_id = AKIA...
aws_secret_access_key = ...

# ~/.aws/config
[default]
region = us-east-1
output = jsonCode language: PHP (php)

If you work with more than one account or role, give each one a named profile. Choose a profile per command with --profile, or for the whole shell session with the AWS_PROFILE environment variable:

aws configure --profile dev
aws s3 ls --profile dev

export AWS_PROFILE=dev
aws configure list          # shows the active profile, region and where each value came from
aws configure list-profilesCode language: PHP (php)

Environment variables override both files. This is the usual way to pass credentials in CI pipelines and containers. The main ones are AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN (for temporary credentials) and AWS_REGION or AWS_DEFAULT_REGION. On EC2, ECS and Lambda, attach an IAM role to the resource instead. The CLI picks up the role's credentials automatically, so you don't need to configure anything.

Recommended: sign in with IAM Identity Center instead of access keys

The aws configure example above uses long-term IAM user access keys. AWS recommends temporary credentials wherever possible. If your organisation uses IAM Identity Center, set up an SSO profile once and then sign in through your browser whenever the session expires:

aws configure sso
# SSO session name: my-sso
# SSO start URL: https://your-portal.awsapps.com/start
# SSO region: us-east-1
# (a browser window opens; approve the request, then choose account and role)

aws sso login --profile my-dev-profile
aws sts get-caller-identity --profile my-dev-profileCode language: PHP (php)

To set up the portal and permission sets this depends on, see AWS Identity Center Guide and AWS Organization and AWS access portal.

Verify, update and uninstall

aws sts get-caller-identity is the most reliable check. It returns the account and identity the CLI is using, and it works even when that identity has no permissions at all:

$ aws sts get-caller-identity
{
    "UserId": "AIDA...",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:user/devops-user"
}Code language: JavaScript (javascript)

To update on Linux, download the latest zip again and run the installer with --update. To uninstall, delete the symlinks and the install directory:

# Update
curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o awscliv2.zip
unzip -qo awscliv2.zip
sudo ./aws/install --update

# Uninstall
sudo rm /usr/local/bin/aws /usr/local/bin/aws_completer
sudo rm -rf /usr/local/aws-cliCode language: PHP (php)

Common errors and fixes

ErrorLikely causeFix
aws: command not found/usr/local/bin isn't on your PATH, or the shell has cached an old location.Run hash -r, check echo $PATH, or reinstall with --bin-dir set to a directory that is on your PATH.
aws --version still shows aws-cli/1.xThe v1 package (or a pip install of v1) appears earlier on your PATH.Run which -a aws, then remove v1 with yum, apt or pip uninstall awscli.
unzip: command not foundThe prerequisite isn't installed.sudo yum install -y unzip or sudo apt-get install -y unzip.
Unable to locate credentialsNo credentials in any profile, environment variable or instance role.Run aws configure or aws sso login, or attach an IAM role to the instance.
InvalidClientTokenId or SignatureDoesNotMatchThe key was copied wrongly, has been deactivated, or the system clock is off.Create a new key pair and sync the clock with NTP (timedatectl).
You must specify a regionNo region set in the profile or the environment.Set region in ~/.aws/config, export AWS_REGION, or pass --region.
AccessDenied on aws s3 lsThe credentials work but the identity has no S3 permission.Run aws sts get-caller-identity to confirm the identity, then grant only the permissions it needs.

Security best practices

  • Use IAM Identity Center or IAM roles instead of long-term access keys. Never create access keys for the root user.
  • If you have to use access keys, rotate them regularly and give the IAM user least-privilege policies.
  • Never commit ~/.aws/credentials to Git or bake it into container images. In pipelines, pass credentials as secrets or environment variables.
  • Restrict the credentials file to your own user: chmod 600 ~/.aws/credentials.
  • Use separate named profiles for dev and prod, and check which one is active with aws configure list before you run commands that change anything.

Frequently asked questions

Should I install AWS CLI v1 or v2?

Install v2. It's the current major version, ships with its own Python runtime, and supports IAM Identity Center (SSO) sign-in. Only use v1 if you're stuck with legacy scripts that depend on it.

How do I check which AWS account the CLI is using?

Run aws sts get-caller-identity. It prints the account ID and ARN for the active credentials. Run aws configure list to see which profile and region are in use and where each value came from.

Where does the AWS CLI store credentials?

Access keys go in ~/.aws/credentials and settings such as region and output format go in ~/.aws/config. On Windows these live in %USERPROFILE%\.aws\. Environment variables override both files.

Why does apt install an old AWS CLI on Ubuntu?

The Ubuntu awscli package is the v1 CLI, and on recent Ubuntu releases it may not be available at all. Use the official bundled installer from AWS, or sudo snap install aws-cli --classic, to get v2.

How do I use multiple AWS accounts with the CLI?

Create a named profile for each account with aws configure --profile name or aws configure sso. Then pass --profile name on each command, or export AWS_PROFILE=name for the whole shell session.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

AWS Tutorials: AWS CodeBuild – Buildspec code for creating AMI from running instances

This page has an AWS CodeBuild buildspec that finds every running EC2 instance tagged environment=uat and creates an AMI from each one with the AWS CLI. It…

Read More

AWS Tutorials: How to Shutdown (Stop / Start) ElastiCache Service in AWS

Amazon ElastiCache has no stop or start button. You keep paying for every node until you shrink or delete it. This guide shows the two ways to…

Read More

AWS Tutorials: AWS S3 Commands Example

The aws s3 commands in the AWS CLI handle everyday Amazon S3 work: creating and removing buckets, uploading and downloading files, moving objects and syncing whole directories….

Read More

AWS CLI Credentials Setup: Configure, Verify, and Secure Access

Learn how to configure AWS credentials with the AWS CLI, verify your identity, and understand where credentials are stored. This updated guide also compares profiles, environment variables, and role-based access.

Read More

EC2 Boot from EBS Explained: Architecture, Trade-offs, and an AWS CLI Workflow

Booting Amazon EC2 instances from Amazon EBS was a major shift from ephemeral root disks to persistent root volumes. This guide explains what changed, why it mattered, and how to use the model safely in modern operations.

Read More

AWS: Route53 a Complete Guide for Domain work

Iโ€™ll show console + CLI where useful and give a quick troubleshooting section at the end. 0) Prereqs 1) Create a public hosted zone for rajesh.com Console…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Skylar Bennett
Skylar Bennett
8 months ago

This blog gives a clear and practical guide on installing and configuring the AWS CLI. I like how it explains the steps in a simple way, from installation to setting up credentials. Itโ€™s very helpful for beginners who want to start using AWS from the command line easily. 

1
0
Would love your thoughts, please comment.x
()
x