[LINUX] Install AWS CLI v2 without sudo

For busy people

It's installed in the root user's directory, so you can just put it in a different directory and put it in your path. If you know what you are doing with this, you may not have to read it afterwards w

As mentioned later, it seems that v1 and v2 are partially incompatible, so be careful when installing with brew from now on.

Main subject

This week, AWS CLI V2 is now GA. AWS Blog Class Method's Blog

Personally, I haven't tried it at all yet, so I'm about to do it, but in order to use it, I have to install it first. How to install is officially listed. My environment is a Mac for both work and personal use, but I originally installed cli with brew. I wanted it to be managed by some package manager.

So I wanted to go with brew if possible, but at the time of writing this can not be installed with brew yet. (So, if you can install it with brew, this content may not be necessary.)

The following is an excerpt of the installation procedure. The installation procedure on Mac is almost the same as the procedure on Linux except that the target file changes.

Installation procedure on Mac


curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-macos.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

The problem is sudo ./aws/install, and I wonder if there are times when a work PC user has limited administrator privileges and can't sudo. I thought I'd try it, but I couldn't, but I'll leave it here because the documentation clearly describes how to avoid it.

Contents of the installation script

I will omit the contents of ./aws/install because it will be long if all the contents are excerpted, but roughly speaking, create a directory called / usr / local / aws-cli, place the program to operate in it, and It seems to work by creating a symbolic link called / usr / local / bin / aws2. I think the reason why you can sudo is that you usually need root privileges to write under / usr. The reason for putting a symlink in / usr / loca / bin is to put a symlink in a directory that is in your PATH so that you can use it from anywhere. (My memory is ambiguous, but did I go through the PATH by default in the first place ...?)

However, it says that you can change the installation directory and the directory where the symbolic link is placed.

Excerpt from the following document

--install-dir or -i

This option specifies a folder to copy all files to. The following example installs the files in a folder named / usr / local / aws-cli. You must have write permission to / usr / local to create this folder.

The default value is / usr / local / aws-cli.

--bin-dir or -b

This option specifies that the main aws program in the installation folder is symbolically linked to the file aws2 in the specified path. In this example, we will create a symbolic link / usr / local / bin / aws2. You need write permission to the specified folder. Creating a symbolic link to a folder that already exists in the path eliminates the need to add the installation directory to the user's $ PATH variable.

The default value is / usr / local / bin.

In other words, you can install it without using sudo by ** putting the file in a suitable directory and placing the symbolic link in any directory in your PATH **.

Change the installation directory

In my case, I created the following directory under the home directory of the user who is using it.

Create a directory and put it in your PATH

mkdir $HOME/awscli2
mkdir $HOME/local/bin

Of course, $ HOME / local / bin is in PATH.

For Bash, go to ~ / .bash_profile

.bash_profile


export PATH=$PATH:$HOME/local/bin

Let's add and reload .bash_profile. Just run source ~ / .bash_profile or restart the terminal and you're good to go.

I'm using fish, so I'm adding it to the universal variable. Note that the method of setting environment variables of fish is a little different from bash and it is a little confusing. .fish/config/config.fishに環境変数を設定するコマンドを追記するのでもいいと思います(お好みで) ただ、下記は永続的な設定なので.fish/config/config.fishのではなくターミナルで一回実行するだけにしましょう。 If the contents of $ fish_user_paths are accidentally emptied, it will be troublesome later (1 loss). reference https://qiita.com/ledsun/items/8ca1a450b21c8ebc9670

fish


set -U fish_user_paths $HOME/local/bin $fish_user_paths

Install with options specified

After that, I specified the option like this at the time of installation.

./aws/install -i $HOME/awscli2/ -b $HOME/local/bin/

Now you can run it, and now a symbolic link is created with the name ʻaws2` for use with v1.

aws2 --version
aws-cli/2.0.0dev4 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev3

From the document

In the AWS CLI version 2 preview release, the symbolic link is named aws2 so that AWS CLI version 1 and version 2 can coexist side-by-side. This command name is subject to change in a future release of AWS CLI version 2.

Anyway, you can now try the V2 aws cli.

Points to be worried about

――It's just ** manual installation **, so if there is an update, you have to do it yourself --There are some backward incompatible changes - https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cliv2-migration.html

Relation

[Use AWS CLI (v1) and AWS CLI v2 properly using venv (Mac, Linux)](https://dev.classmethod.jp/cloud/aws/separate-aws-cli-v1-and-v2- with-venv-for-mac-and-linux /) Install AWS CLI v2 from source code

Recommended Posts

Install AWS CLI v2 without sudo
sudo pip install
[Node] [npm] Install npm packeage on MacOS / Linux without sudo
Install Docker on AWS
ArcoLinux v20 xfce install
Install openblas (without apt-get)
Run YOLO v3 on AWS v2
Run YOLO v3 on AWS
Install CaboCha without root privileges.