16

As title suggested, I haven't been able to find a good way to install aws-cli (https://github.com/aws/aws-cli/) without having the root access (or equivalent of sudo privileges).

The way Homebrew setup on Mac is hinting at it may be possible, provided that a few directories and permissions are set in a way to facility future installs. However, I have yet to find any approach in Linux (specially, Red Hat Enterprise Linux or CentOS distroes).

I am also aware of SCL from RHEL (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Developer_Guide/scl-utils.html) But again, it requires sudo.

Devy
  • 9,655
  • 8
  • 61
  • 59

8 Answers8

28

There's a bundled installer for that purpose.

Install aws command to $HOME/bin

$ wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
$ unzip awscli-bundle.zip
$ ./awscli-bundle/install -b ~/bin/aws

Set $PATH environment variable

$ echo $PATH | grep ~/bin     // See if $PATH contains ~/bin (output will be empty if it doesn't)
$ export PATH=~/bin:$PATH     // Add ~/bin to $PATH if necessary

Test the AWS CLI Installation

$ aws help

See the following link for details: http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-bundle.html#install-bundle-user

quiver
  • 4,230
  • 1
  • 22
  • 20
17

For AWS CLI v2, the recommended solution is passing options -i and -b when installing indicating directories for which user has write permissions.

Example:

$ cd Downloads
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ ./aws/install -i ~/aws-cli -b ~/aws-cli/bin

From Amazon Web Service's documentation:

You can install without sudo if you specify directories that you already have write permissions to. Use the following instructions for the install command to specify the installation location:

  • Ensure that the paths you provide to the -i and -b parameters contain no volume name or directory names that contain any space characters or other white space characters. If there is a space, the installation fails.

  • --install-dir or -i – This option specifies the directory to copy all of the files to.

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

  • --bin-dir or -b – This option specifies that the main aws program in the install directory is symbolically linked to the file aws in the specified path. You must have write permissions to the specified directory. Creating a symlink to a directory that is already in your path eliminates the need to add the install directory to the user's $PATH variable.

    The default value is /usr/local/bin.

(I believe the accepted answer is outdated in that it only works for AWS CLI v1.)

oguz ismail
  • 1
  • 16
  • 47
  • 69
Thiago Gouvea
  • 543
  • 4
  • 12
  • I think it would make more sense to put the binary in your user's binary directory instead: `./aws/install -i ~/aws-cli -b ~/bin` – scottclowe Jul 16 '21 at 12:56
  • Actually, better to put it in .local/bin: `./aws/install -i ~/.local/aws-cli -b ~/.local/bin` – scottclowe Jul 16 '21 at 13:34
2

Obviously, the answers is possible. The trick is to install the whole stack in an alternate location on the host machine.

So altinstall python, then easy_intsall, then pip. Here are the command history in my log.

cd
mkdir installations
cd installations/
curl -O https://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
tar xjf Python-2.7.tar.bz2 
cd Python-2.7
mkdir -p ~/usr/local
make altinstall prefix=~/usr/local exec-prefix=~/usr/local
~/usr/local/bin/python2.7 -V
ln -s ~/usr/local/bin/python2.7 ~/usr/local/bin/python
echo "export $PATH=~/usr/local/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
cd
mkdir virtualenv
cd virtualenv/
curl -O https://raw.github.com/pypa/virtualenv/master/virtualenv.py
mkdir ~/envs
python virtual-python.py --prefix=~/env/aws
curl -O http://peak.telecommunity.com/dist/ez_setup.py
~/env/aws/bin/python ez_setup.py
echo "export $PATH=~/env/aws/bin:~/usr/local/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
easy_install virtualenv
virtualenv --no-site-packages ~/env/awscli
source ~/env/awscli/bin/activate
pip -V
pip install awscli

These are helpful links that I followed to help me achieve that goal.

Install Python in an alternate location

Install Python stack without root privilege

Community
  • 1
  • 1
Devy
  • 9,655
  • 8
  • 61
  • 59
1

You can install without root access with the --user flag to pip:

pip install --user -U awscli

(Hat tip to Etan Reisner who wrote this in a comment).

sligocki
  • 6,246
  • 5
  • 38
  • 47
0

After installing aws on my ubuntu 20.04, I faced same issue. when I tried:

aws --version

it didn't worked (Command 'aws' not found, but can be installed with: sudo apt install awscli) and

/usr/local/bin/aws --version
aws-cli/2.3.1 Python/3.8.8 Linux/5.11.0-38-generic exe/x86_64.ubuntu.20 prompt/off

Then I can't use aws without sudo privileges

I fixed it by (by adding rights for group and others on /usr/local/aws-cli directory)

sudo chmod -R 755 /usr/local/aws-cli

And it works for me! Let me know if it's ok for you!

Ibrahima Timera
  • 598
  • 4
  • 7
0

The answer by Quiver works like a charm, except that there is a prerequisite. You need to have Python installed too. Given that you don’t have root privileges, you will now end up searching for how to install python without root permission, and that ain’t going to be straightforward either. 


So here is the complete solution that finally worked for me.

  1. Install Anaconda with wget


cd ~
wget https://repo.continuum.io/archive/Anaconda3-2020.11-Linux-x86_64.sh
bash Anaconda3-2020.11-Linux-x86_64.sh -b -p ~/anaconda3    # Install aws command to $HOME/bin
echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc

~/anaconda3/bin/conda init  # Reload default profile
source ~/.bashrc
  1. Use the bundled installer to install aws-cli package
wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
unzip awscli-bundle.zip
./awscli-bundle/install -b ~/bin/aws

export PATH=~/bin:$PATH
  1. Test the AWS CLI Installation

aws —version
and_roid
  • 1
  • 1
0
namei -l /usr/local/bin/aws

shows the permissions of each path leading to the actual aws script.

sudo chmod 777 fixes the permissions for the path that's lacking access from your non-root user.

Slawa
  • 1,141
  • 15
  • 21
-1

I use conda to install asw cli:

conda install -c conda-forge awscli

You don't need root permission to install conda.

Michael Chao
  • 570
  • 5
  • 14