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.
- Solution 1: Adding Ansible installation path to system $PATH variable
- Solution 2: Use full path to the Ansible Binary (Not recommended)
- Solution 3: Create an alias for the Ansible command
- Solution 4: Install Ansible using a package manager
- 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:
- 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.
- 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:
- Run the command below to reload your shell configuration file after saving the changes:
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.
Solution 2: Use full path to the Ansible Binary (Not recommended)
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
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:
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 -
- apt (for Ubuntu/Debian) - Here are the command to install the ansible on debian based system
1sudo apt update 2sudo apt install ansible
- yum (for Red Hat/CentOS) - Here are the command to install the ansible on CentOS/Red Hat Linux
1sudo yum install ansible
- 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:
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
- Ansible Handlers Explained Real-World Use Cases & Examples?
- How to Use SSH Keys with Ansible for Secure Server Management?
- Why YAML is so important in Ansible?
- Clone Public and Private Git Repositories with Ansible
- How to Limit Ansible playbook on Hosts, Groups and multiple hosts?
- Easy Fix for 'zsh command not found ansible' Error After Installing Ansible with Pip
- Demystifying Hosts, Inventory Roles, and Tasks
- Fixing-Unable to start service apache2 Job for apache2.service failed because the control process exited with error code?
- Why Ansible is the Ultimate Tool for DevOps Teams - A Beginner's Guide?
- Ansible how to fix destination path already exists and is not an empty directory?
- Install Ansible on MacOS, Windows, Ubuntu(debian) and Fedora(rpm) - Part 1