skip to Main Content

Installed aws cli 2 on my Centos machine. Added

PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"

to /etc/environment. Most of the cases aws command can be called successfully. However, when using sudo aws, it shows command not found. Below are all the scenarios. Any idea?

[centos@ip-172-20-x-x ~]$ aws --version
aws-cli/2.1.28 Python/3.8.8 Linux/3.10.0-1160.11.1.el7.x86_64 exe/x86_64.centos.7 prompt/off
[centos@ip-172-20-x-x ~]$ sudo su
[root@ip-172-20-x-x centos]# aws --version
aws-cli/2.1.28 Python/3.8.8 Linux/3.10.0-1160.11.1.el7.x86_64 exe/x86_64.centos.7 prompt/off
[root@ip-172-20-x-x centos]# sudo aws --version
sudo: aws: command not found
[root@ip-172-20-x-x centos]# cat /etc/environment
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"
[root@ip-172-20-x-x centos]# sudo env
HOSTNAME=ip-172-20-x-x.ap-southeast-1.compute.internal
TERM=xterm
HISTSIZE=1000
USERNAME=root
MAIL=/var/spool/mail/centos
LANG=en_US.UTF-8
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
LOGNAME=root
USER=root
HOME=/root
SHELL=/bin/bash
SUDO_COMMAND=/bin/env
SUDO_USER=root
SUDO_UID=0
SUDO_GID=0
XDG_SESSION_ID=20

2

Answers


  1. Not sure how you installed the CLI, and why do you need sudo for aws cli.

    Assuming you have sudo privileges on the machine, can install using the below command, from the post I can see you already have /usr/local/bin already in the root path.

    The installation command uses a file named install in the newly unzipped aws directory. By default, the files are all installed to /usr/local/aws-cli, and a symbolic link is created in /usr/local/bin. The command includes sudo to grant write permissions to those directories

    curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
    unzip awscliv2.zip
    sudo ./aws/install
    

    Alternately you can simply update the root path with the aws cli path available for centos non root-user.

    To find out the path for aws cli you can use which command

    $ which aws
    /usr/local/bin/aws
    
    export PATH=<AWS CLI PATH>:$PATH 
    

    Installing, updating, and uninstalling the AWS CLI version 2 on Linux

    Login or Signup to reply.
  2. First of all, install awscli correctly using pip: you may have installed it with apt ,but although the awscli package is available in repositories for other package managers such as apt and yum, these are NOT produced, managed, or supported by AWS.
    So, if u didn’t installed with pip, try reinstalling awscli as follows:

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

    Otherwise, if you have installed awscli using the bundled installer without sudo, you must know that this installs the AWS CLI to the default location (~/.local/lib/aws) and creates a symbolic link (symlink) at ~/bin/aws. Make sure that ~/bin is in your PATH environment variable for the symlink to work, as follows:

    $ 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
    

    For any doubt, visit the official documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search