How to upgrade AWS CLI to the latest version?
Asked Answered
B

19

174

I recently noticed that I am running an old version of AWS CLI that is lacking some functionality I need:

$aws --version
aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic

How can I upgrade to the latest version of the AWS CLI (1.10.24)?

Edit:

Running the following command fails to update AWS CLI:

$ pip install --upgrade awscli
Requirement already up-to-date: awscli in /usr/local/lib/python2.7/dist-packages
Cleaning up...

Checking the version:

$ aws --version
aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic
Berns answered 1/5, 2016 at 17:4 Comment(3)
I had this same situation and was caused by the aws cli being originally installed via apt-get install awscli. Solution was to remove it first (apt-get remove awscli) and follow pip install answers below.Preview
I did (apt-get remove awscli) but then after following (pip install...) commands I can't find the awscli executable. The output of (pip install ...) says successfully installed.Morbidity
If I don't use "--user" option in pip install then I could find awscli executable under /usr/local/bin (I am on Debian Jessie). But with --user option the exec is not available in ~/.local or in any of the python installation package folders (dist-package or site-package).Morbidity
D
139

From http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-with-pip

To upgrade an existing AWS CLI installation, use the --upgrade option:

pip install --upgrade awscli
Datnow answered 1/5, 2016 at 17:7 Comment(10)
I get the following message: Requirement already up-to-date: awscli in /usr/local/lib/python2.7/dist-packages. Although when I run aws --version, I get aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic.Berns
Try pip3 install --upgrade awscliDias
Running sudo pip3 install --upgrade awscli and a reboot did the trick. Thanks for the help.Berns
Just a reboot is required after installing aws cli.Denti
I can't believe a reboot is required, but in this case it was faster to reboot my vm than find an alternative [that 'reboot voodoo' is for windows].Logarithmic
If PyYAML failed you while installing: pip uninstall awscli, then sudo apt-get install python-dev and pip install awscli again.Overscrupulous
For me helped going sudo su first.Pretorius
you don't need to reboot, just enter to another terminal, or restart the current oneForeshadow
I now have aws and aws2 in my systems. How do I get rid of aws and rename my aws2 as aws?Isle
Instead of reboot or starting another shell, you can run "hash -r" to clear the remembered utility locations. Or "hash aws" to reset just the remembered aws executable location.Cavafy
P
53

On Linux and MacOS X, here are the three commands that correspond to each step:

$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Persuader answered 4/2, 2017 at 21:44 Comment(5)
updating via pip did not work for me - deleting aws and re-installing it this way did work.Iconium
You saved my day. AWS is getting poor on its documentation.Holbein
this option worked for me as I needed to upgrade /usr/local/aws ( not /home/ubuntu/.local/bin/aws ) to be used by jenkins userUtopian
The documentation of AWS is indeed deteriorating rapidly. This is the correct answer, I can't understand why the questioner accepted an answer which they'd clearly stated in their edit didn't work - the pip packages are often behind the current latest which is a problem when using new stuff like EKS. Note: I had to exit the shell and log back in for the aws command to pick up the new version. No idea why.Enrapture
If you are using python3 run sudo /usr/local/bin/python3.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws instead of sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/awsFriedman
H
25

This does not work:

pip install --upgrade awscli

This worked fine on Ubuntu 14.04( no need to reboot also .. You would have to first install pip3 ):

pip3 install --upgrade awscli

Helyn answered 15/12, 2016 at 18:52 Comment(1)
This may require: apt-get install python3-pip Either command works equally well for me on Ubuntu 14.04.Seaden
R
13

For Ubuntu 16.04 I used parts of the other answers and comments and just reloaded bash instead of rebooting.

I installed the aws-cli using apt so I removed that first:

sudo apt-get remove awscli

Then I could pip install (I chose to use sudo to install globally with pip2):

sudo pip install -U awscli

Since I was doing this on a server I didn't want to reboot it, but reloading bash did the trick:

source ~/.bashrc

At this point I could use the new version of aws cli

aws --version
Rubyeruch answered 31/1, 2018 at 21:59 Comment(1)
Thanks for source ~/.bashrc step.:)Madelinemadella
D
12

Update: Upgrade instance using AWS CLI v2:

This question and answer was initially created when there was only an AWS CLI v1. There is now a AWS CLI v2. The installation instructions for the AWS CLI v2 can be found here.

The new AWS CLI v2 has different installation instructions based on whether your EC2 instance is using Linux x86 (64-bit) or Linux ARM architecture.

For Linux x86 (64-bit) architecture execute the following commands as the root user:

aws --version

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

aws --version

Verify that the AWS CLI actually upgraded by looking at the output of the: aws --version commands.

Let's clean up after ourselves:

rm -rf aws
rm -f awscliv2.zip

For Linux ARM architecture it might work to just replace the preceding curl command with the following as per the documentation:

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

Original answer: Upgrade instance using AWS CLI v1 to use the most recent version of AWS CLI v1:

If you are having trouble installing the AWS CLI using pip you can use the "Bundled Installer" as documented here.

The steps discussed there are as follows:

$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Check your AWS CLI version subsequently as a sanity-check that everything executed correctly:

$ aws --version

If the AWS CLI didn't update to the latest version as expected maybe the AWS CLI binaries are located somewhere else as the previously-given commands assume.

Determine where AWS CLI is being executed from:

$ which aws

In my case, AWS CLI was being executed from /bin/aws, so I had to install the "Bundled Installer" using that location as follows:

$ sudo ./awscli-bundle/install -i /user/local/aws -b /bin/aws
Derte answered 14/10, 2019 at 3:22 Comment(3)
using the bundled installer somehow makes the resulting docker image LARGER than using pip ... mind blowingLaborious
It may be necessary to open a new shell after installing - for some reason "aws" doesn't point to the new install until exiting and restarting.Enrapture
@chad-grant Did you delete the bundled installer subsequently to using it? I've updated my answer to just do some cleanup.Derte
C
8

Try sudo pip install --upgrade awscli, and open a new shell. This worked well for me (no need to reboot).

Contemporary answered 31/7, 2017 at 21:43 Comment(1)
On Mac OS, I had to run sudo pip install --upgrade awscli for my machine to be able to uninstall the previous version of the awscli (after the initial upgrade ran successfully)Becka
M
5

Simple use sudo pip install awscli --force-reinstall --upgrade

This will upgrade all the required modules.

Misadventure answered 27/12, 2018 at 3:34 Comment(1)
on my jenkins machine I didn't want to explicitly uninstall the cli, so I used this method and worked like a charm!Cards
C
4

On Mac you can use homebrew:

to install: brew install awscli

to upgrade: brew upgrade awscli

Make sure you don't have multiple installations: where aws

Cerebrate answered 5/4, 2020 at 9:56 Comment(0)
S
2
pip install awscli --upgrade --user

The --upgrade option tells pip to upgrade any requirements that are already installed. The --user option tells pip to install the program to a subdirectory of your user directory to avoid modifying libraries used by your operating system.

Sadden answered 1/10, 2019 at 15:24 Comment(0)
R
0

We can follow the below commands to install AWS CLI on UBUNTU:

sudo apt install curl

curl “https://s3.amazonaws.com/aws-cli/awscli-bundle.zip” -o “awscli-bundle.zip”

unzip awscli-bundle.zip

sudo ./awscli-bundle/install -i /usr/local/ aws -b /usr/local/bin/aws

rm -rf awscli-bundle.zip awscli-bundle

To test: aws — version

For More Info :

https://gurudathbn.wordpress.com/2018/03/31/installing-aws-cli-on-ubuntu/

Reluct answered 4/4, 2018 at 9:58 Comment(0)
S
0

When using sudo pip install --upgrade awscli I got the following error:

ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: '/lib'

By using sudo with -H option, I could fix the problem.

sudo -H pip install --upgrade awscli
Soria answered 6/2, 2020 at 11:25 Comment(0)
E
0

Currently, using pip will get you the old version of awscli, 1.18.103.

The latest version of aws-cli, 2.0.33 is on the v2 branch. You can download the installer for Linux, Windows and macOS from here.

Embolic answered 23/7, 2020 at 8:48 Comment(0)
R
0

I was trying to install awscli on one of my ec2 instances where I tried both

  • sudo pip install --upgrade awscli,
  • sudo pip3 install --upgrade awscli

which didn't worked, as I was getting errors like

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-2nh71cs2/cryptography/

And rebooting servers were not an option.

Luckily, simple

  • sudo apt update
  • sudo apt install awscli worked.
Rackrent answered 14/6, 2021 at 7:39 Comment(0)
M
0

I do it by removing & installing the awscli like described in this video

basically:

pip uninstall awscliv2

pip install awscliv2

pip install awscliv2==your-version

pip install awscliv

(you can keep v1 along with v2 if you want)

pip install --upgrade ...

works as well. sure.

I do not install it globally (like some ppl seems still do), btw. Because sometimes I need different v for different cases. so I keep it in separate python virtual environment.

Moon answered 22/2, 2022 at 0:46 Comment(0)
N
0

For windows you can try this command

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Niagara answered 28/9, 2022 at 20:6 Comment(0)
N
0

Install or update the AWS CLI on macOS

  1. curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
  2. sudo installer -pkg ./AWSCLIV2.pkg -target /

Done! You can verify the same with below cmd

  • aws --version
Nabataean answered 8/2, 2023 at 9:15 Comment(0)
C
0

An adaptation of the answer provided by dutoitns to upgrade an EC2 instance to the latest AWS CLI v2: (AL2, as of 2023/11) -

ec2_to_awscli2() {
  # uninstall awscli v1, and install latest v2
  aws --version;
  pip3 uninstall awscli -y;
  sudo yum remove awscli -y;
  if [[ "$(uname -m)" =~ aarch64 ]]; then arch="aarch64"; else  arch="x86_64"; fi
  curl "https://awscli.amazonaws.com/awscli-exe-linux-${arch}.zip" -o "awscliv2.zip";
  unzip awscliv2.zip;
  sudo ./aws/install;
  rm -rf aws; rm -f awscliv2.zip;
  hash aws
  aws --version
}

ec2_to_awscli2

This alleviates the need to know the architecture of the instance and hashes the aws alias so that the most recent cli is immediately usable.

Corinacorine answered 8/11, 2023 at 19:33 Comment(0)
M
-1

Try AWS Cloud Shell, Quick and easy

AWS CloudShell is a browser-based shell that makes it easy to securely manage, explore, and interact with your AWS resources. CloudShell is pre-authenticated with your console credentials.

Benefits

  • No extra credentials to manage
  • Always up to date
  • No cost

More Details here https://aws.amazon.com/cloudshell/

  • Customizable
Magnificence answered 10/3, 2021 at 5:1 Comment(1)
Until unless used for a specific purpose, common day to day operations could easily be handled with Cloud shellMagnificence
G
-3

To install globally, get on the sudo access sudo su & then upgrade aws cli by

pip3 install --upgrade awscli
Gerhart answered 19/7, 2021 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.