Installing Ansible on Linux

Installing Ansible on Linux is a simple process and can be done in different ways. The most common ways to install Ansible on Linux are using the package manager or using pip into a virtual environment.

Installing Ansible using package manager

Installing Ansible using package manager is the easiest way to install Ansible on Linux. The package manager will take care of all the dependencies and install the required packages.

For example, to install Ansible on Ubuntu, you can use the following command:

Installing Ansible on Debian / Ubuntu based systems
sudo apt-get update
sudo apt-get install ansible

This will install Ansible on your system along with all the required dependencies.

Installing Ansible on Red Hat based systems
sudo dnf install ansible

Installing Ansible using pip

If you prefer to install Ansible using pip, you can do so by running the following command:

Installing Ansible using pip
pip install ansible

This will install Ansible on your system along with all the required dependencies.

Note

It is recommended to install Ansible in a virtual environment to avoid conflicts with other Python packages.

Installing Ansible in a virtual environment
python3 -m venv ansible-env
source ansible-env/bin/activate
pip install ansible

Ansible can also be installed under the user’s home directory using the --user option.

Installing Ansible under the user’s home directory
pip install --user ansible

Verifying the installation

Once you have installed Ansible, you can verify the installation by running the following command:

Verifying the installation
ansible --version

This will display the version of Ansible installed on your system and other relevant information like the Python version and the location of the configuration file.