Easy Fix for 'zsh command not found ansible' Error After Installing Ansible with Pip

It's conceivable that the directory where pip installed Ansible is not in your system's PATH environment variable if you used pip to install Ansible and are getting the error message -

1zsh: command not found: ansible. 

There are a few options for fixing this issue depending on your local Ansible configuration. So please go over both alternatives and choose the one that makes the most sense.

  1. Solution 1: Adding Ansible installation path to system $PATH variable
  2. Solution 2: Use full path to the Ansible Binary (Not recommended)
  3. Solution 3: Create an alias for the Ansible command
  4. Solution 4: Install Ansible using a package manager
  5. Solution 5: Check if pip installed Ansible in a user-specific location

Solution 1: Adding Ansible installation path to system $PATH variable

This problem may be resolved by setting the PATH environment variable on your system to include the location where Ansible is installed. Follow these steps to accomplish this:

  1. Ansible Installation Location - Determine the location where Ansible is installed. You can use the following command to find the location:
1pip3 show ansible

This command will display the information about the Ansible package, including the location where it is installed.

zsh command not found ansible verify ansible by running pip3 show ansible

  1. Add Ansible Location to Path Environment- When you have located Ansible's installation location, add it to your system's PATH environment variable.

The following line need be added to your shell configuration file (.bashrc or.zshrc) to do this:

1export PATH=$PATH:/path/to/ansible
  1. Run the command below to reload your shell configuration file after saving the changes:
1source ~/.zshrc 

This will change the PATH environment variable and reload the shell configuration file.

These instructions should enable you to run the "ansible" command without any problems.


When executing Ansible commands, you may use the full path to the Ansible binary rather than depending on the PATH environment variable to locate the Ansible binary.

You may launch Ansible by using the command /usr/local/bin/ansible, for instance, if it is installed in /usr/local/bin/ansible.

Note- The above mentioned method will typically work, however using the complete path of the Ansible binaries to execute the playbooks is always quite inconvenient. I would recommend using creating alias for the Ansible binary path, refer to Solution 3 for creatin alias.


Solution 3: Create an alias for the Ansible command

In the configuration file for your shell, you may define an alias for the ansible command.

For instance, you may include the line below in your .zshrc file:

1alias ansible="/path/to/ansible"

Note - Replace /path/to/ansible with the actual location where Ansible is installed. This will create an alias for the Ansible command that can be used instead of the full path.


Solution 4: Install Ansible using a package manager

Using a package management to install Ansible is an alternative to using pip. You may use following package manager to install Ansible based on the operating system -

  1. apt (for Ubuntu/Debian) - Here are the command to install the ansible on debian based system
1sudo apt update
2sudo apt install ansible
  1. yum (for Red Hat/CentOS) - Here are the command to install the ansible on CentOS/Red Hat Linux
1sudo yum install ansible 
  1. brew (for macOS) - Here is the brew command to install Ansible on MacOS
1brew install ansible

If Ansible is installed through a package management, the binary will be added to the PATH environment variable and will work without a hitch.

Refer to this detailed article for more in-depth installation instruction of Ansible


Solution 5: Check if pip installed Ansible in a user-specific location

You might need to add that directory to your PATH environment variable if pip installed Ansible in a user-specific place (such ~/.local/bin).

To accomplish this, add the next line to your .zshrc file:

1export PATH=$PATH:~/.local/bin 

This will add the user-specific bin directory to your PATH environment variable.

By following these steps, you should be able to troubleshoot and resolve the "zsh: command not found: ansible" error after installing Ansible using pip.

Posts in this series