AWS CLI command not found – quick fixes

When it comes to handling AWS services, you can solely rely on the AWS Command Line Interface (AWS CLI). You can control multiple AWS services from the command line and automate them with just one tool to download and configure.

AWS CLI supports Windows, Linux, macOS, and Docker containers and can be automated easily by writing Python scripts.

In this short article, we will show you a few possible solutions to fix “aws: command not found” error message in Linux.

Check python command

The “command not found” error message usually indicates that the system cannot locate executable files. But in AWS CLI case, things can be different, depending on how you installed it.

AWS CLI is a Python program, which means it uses the python command for most of its internal works. On modern Linux system, such as Ubuntu 22.04, the python command is now deprecated in favor of python3. That can mess up the aws command if you have installed it from PyPI or using an automated script.

If you install AWS CLI using the package manager for your system (apt, yum, etc…), then Python is almost always guaranteed to work, as the package have been tested throughly by the OS maintainers.

With that said, you should check your python command to see whether it points to the right Python version. To do that, run which python, if the terminal outputs python not found, you now have a few options:

  • Installing python-is-python3 package if you’re on Ubuntu, which points python command to Python 3, which is preinstalled on most Ubuntu-based distribution.
  • Manually adding python as a Python 3 alias in the shell startup profiles.
  • Create a symlink to point python to python3 binary.

Adding python as python3 alias

If you’re using Bash shell, add alias python=python3 to the very end of your ~/.bash_profile.

nano ~/.bash_profile

Similarly, putting alias python=python3 to the bottom of ~/.zshrc file will make ZSH recognizes python command.

You may need to logout and re-login for the changes to take effect.

Link python to python3 binary

Aternatively, you can try creating a symbolic link (symlink) from python to python3 binary.

First, find out where is python3 by running which python3. If you see /usr/bin/python3 as the output, /usr/bin/ is the directory we’re looking for.

Run sudo ln -s /usr/bin/python3 /usr/bin/python to create a symbolic link.

From now on, python command will always run Python 3.

Once you’re done one of the fixes above, try rebooting your system and run aws --version to see if AWS CLI works again or not.

Restart your terminal

If you cannot find the aws command after installing or upgrading the AWS CLI, you may need to restart your terminal for the shell to detect any PATH modifications. Also, reboot your system achieves the same result

Check your permissions

One more possible cause to aws: command not found is the AWS CLI does not have the necessary execute permissions.

If the aws command cannot be found after installing or upgrading the AWS CLI on Linux, it is possible that it might not have execute permissions for the folder it installed in. To give the AWS CLI chmod permissions, run the following command with the PATH to your AWS CLI installation:

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

Adding AWS CLI to your PATH

Most operating systems look for executables and binaries in a specific set of places. The list of all those places is stored in an environment variable, often named PATH.

You may need to add the aws executable to your operating system’s PATH environment variable, as the installation script may fail to do so. Follow the instructions below to add the AWS CLI to your PATH.

Add the AWS CLI to PATH on Linux/macOS

  • Find your shell’s profile script in your user directory. If you’re not sure which shell you have, run echo $SHELL. With Bash, config files are .bash_profile.profile, or .bash_login. ZSH uses .zshrc and Tcsh relies on .tcshrc.cshrc, or .login for configuration.
  • Add an export command to append your local bin to the current PATH variable.
export PATH=`/usr/local/bin`:$PATH
Code language: JavaScript (javascript)
  • Reload the updated profile into your current session.
source ~/.bash_profile

Add the AWS CLI to PATH on Windows

  • Open up the Command Prompt, run where /R c:\ aws to find the aws file location. The results return all folders containing aws. By default, the AWS CLI version 2 is located in C:\Program Files\Amazon\AWSCLIV2\aws.exe.
  • Open the Start, search for “env”, then choose “Edit the system environment variables”.
  • Select “Environment Variables…”
  • Find the variable called “Path” and click “Edit…”, then click “New”.
  • Enter the path to the folder containing the binary you want on your PATH, which is taken from the first step. Usually, the path is C:\Program Files\Amazon\AWSCLIV2\aws.exe.

Install aws

It’s obvious, but you may have forgotten to install AWS CLI in the first place or something have messed up your installation. Follow the instructions below to install AWS CLI version 2.

Install AWS CLI on Debian and Ubuntu

AWS CLI is available as a package, ready to be installed in Debian and Ubuntu official repository. In order to have aws command installed on your Debian-based system, run the following command:

sudo apt install awscli -y

Install AWS CLI using official scripts

From version 2, Amazon have included an AWS CLI installation script for Linux, macOS and Windows. They are the preferred way to install AWS CLI, as they contains the latest version of the software including bug fixes and security patches. As installation details change with time, it is best to consult the official Install/Update AWS Command Line Interface page for more information.

We hope that the information above is useful and helped you successfully fix the “aws: command not found” error.

If you’re also seeing a “command not found” error message, you may want to check out our other guides to fix zsh: command not found,  time: command not found and nodemon: command not found.

If you have any questions, then please feel free to ask in the comments below.

Leave a Comment