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
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.Alternately you can simply update the
root
path with theaws cli
path available forcentos
non root-user.To find out the path for aws cli you can use
which
commandInstalling, updating, and uninstalling the AWS CLI version 2 on Linux
First of all, install
awscli
correctly usingpip
: you may have installed it withapt
,but although theawscli
package is available in repositories for other package managers such asapt
andyum
, these are NOT produced, managed, or supported by AWS.So, if u didn’t installed with pip, try reinstalling
awscli
as follows:Otherwise, if you have installed
awscli
using the bundled installer without sudo, you must know that this installs theAWS CLI
to the default location(~/.local/lib/aws)
and creates a symbolic link (symlink) at~/bin/aws
. Make sure that~/bin
is in yourPATH
environment variable for the symlink to work, as follows:For any doubt, visit the official documentation.