How to Install Ansible on Linux, Mac, and Windows

Install Ansible on Ubuntu Mac Windows

Ansible is a powerful automation tool used for configuration management, application deployment, and task automation. It’s known for its simplicity and ease of use, making it a popular choice among DevOps professionals.

This guide will show you how to install Ansible on Linux, Mac, and Windows operating systems.

Installing Ansible on Linux

In this section, we will show you how to install Ansible on popular Linux distributions such as, Ubuntu, Debian, CentOS, Fedora and RHEL.

Install Ansible on Ubuntu/Debian

1. Update the package index to ensure that you have the latest information on the newest versions of packages and their dependencies.

 # apt update -y

2. Install the required dependencies.

 # apt install -y software-properties-common

3. Add the Ansible PPA to get the latest stable release of Ansible.

 # add-apt-repository --yes --update ppa:ansible/ansible

4. With the repository added, you can now install Ansible.

 # apt install -y ansible

Installing Ansible on CentOS/RHEL

1. Enable the EPEL repository.

 # yum install -y epel-release

2. With the EPEL repository enabled, you can install Ansible using the yum package manager.

 # yum install -y ansible

Installing Ansible on Fedora

1. Update the package index to get the latest package version.

 # dnf update -y

2. Install Ansible using the dnf package manager.

 # dnf install -y ansible

Install Ansible Using PIP

PIP (Python Package Installer) is a versatile tool for installing Python packages, including Ansible. This method is useful when you want more control over the version of Ansible you install or if the package manager doesn’t have the latest version.

1. Install PIP

First, ensure you have PIP installed on your system. You can install it using your package manager if it’s not installed.

For Ubuntu/Debian:

 # apt install -y python3-pip

For CentOS/RHEL:

 # yum install -y python3-pip

For Fedora:

 # dnf install -y python3-pip

2. Install Ansible Using PIP

With PIP installed, you can install Ansible. This method lets you install the latest version directly from the Python Package Index (PyPI).

 # pip3 install ansible

Installing Ansible on Mac

1. Install Homebrew. You can install it by running the following command in your terminal if it has not already been installed. This command will download and install Homebrew.

 # /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Update the Homebrew to ensure that you have the latest package definitions.

 # brew update

3. With Homebrew updated, you can now install Ansible. This command will download and install Ansible with any required dependencies.

 # brew install ansible

Installing Ansible on Windows

There are two methods to install Ansible on Windows.

Method 1: Using WSL (Windows Subsystem for Linux)

WSL allows you to run a Linux distribution alongside your Windows installation. This method provides a native Linux experience, making installing and using Ansible easier.

1. Enable WSL

Open PowerShell as Administrator and run the following command to enable WSL. This command will install the necessary components for running a Linux distribution on Windows.

 # wsl --install

2. Install a Linux Distribution

After enabling WSL, you can install a Linux distribution like Ubuntu from the Microsoft Store. This will provide a complete Linux environment within Windows.

3. Open the Linux Distribution

Once installed, open the Linux distribution from the Start menu. This will launch a terminal window with your chosen Linux distribution.

4. Update the Package Index

Updating the package index ensures you have the latest information on the newest versions of packages and their dependencies. This helps in avoiding potential conflicts and ensures you install the latest version of Ansible.

 # apt update -y

5. Install Required Dependencies

Installing software-properties-common provides the add-apt-repository command, simplifying the process of adding PPA (Personal Package Archives) to your system.

 # apt install -y software-properties-common

6. Add Ansible PPA

Ansible’s PPA contains the latest stable release of Ansible. Adding this repository ensures you get the latest version directly from Ansible’s maintainers.

 # add-apt-repository --yes --update ppa:ansible/ansible

7. Install Ansible

With the repository added, you can now install Ansible. The -y flag automatically confirms the installation of the package.

 # apt install -y ansible

Method 2: Using Cygwin

Cygwin provides a large collection of GNU and Open Source tools that provide functionality similar to a Linux distribution on Windows. This method allows you to run Ansible in a Unix-like environment on Windows.

1. Download and Install Cygwin

Download the Cygwin installer from here and run it. Follow the prompts to install Cygwin on your system.

2. Select Packages

During installation, ensure you select the following packages: python3, python3-pip, and git. These packages are necessary for installing and running Ansible.

3. Install Ansible via Pip

Open the Cygwin terminal and run the following command to install Ansible using Pip. This method lets you install the latest version directly from the Python Package Index (PyPI).

 # pip3 install ansible

Verifying the Installation

After installation, you can verify that Ansible is installed correctly by checking the version. This step ensures that Ansible was installed successfully and is ready for use.

 # ansible --version

You should see output similar to the following, indicating the version of Ansible installed:

check ansible version

Uninstalling Ansible on Linux, Windows, and Mac

Here’s how you can uninstall Ansible from different operating systems, including Linux, Windows, and macOS:

Uninstall Ansible on Linux

For Ubuntu/Debian:

 # apt remove ansible

For CentOS/Fedora:

 # yum remove ansible

Using pip:

If you installed Ansible using pip, run the following command to uninstall it:

 # pip uninstall ansible

Uninstall Ansible on Windows

Ansible is not directly installed on Windows, but you may have set it up via Windows Subsystem for Linux (WSL) or using a Linux virtual machine. Here’s how to remove it:

Uninstalling from WSL:

Launch WSL (e.g., Ubuntu) and use the respective package manager to remove Ansible:

 # apt remove ansible

Uninstall Ansible on Mac

On macOS, the method to uninstall Ansible depends on how it was installed.

Using Homebrew

If you installed Ansible using Homebrew, you can remove it with:

 # brew uninstall ansible

Using pip

If you installed Ansible using pip, use the following command to uninstall it:

 # pip uninstall ansible

Conclusion

Congratulations! You have successfully installed Ansible on Linux, Mac, and Windows. It is now ready to automate your IT infrastructure. Whether you are managing a few servers or a large fleet, Ansible simplifies your tasks with its powerful automation capabilities.

If you have any questions or run into any issues, the Ansible documentation and community are excellent resources for additional support.

FAQs

1. Is it possible to use Ansible on Windows without WSL?

Ansible is not natively supported on Windows. You need WSL or a virtual machine running Linux.

2. What are the prerequisites for installing Ansible on Linux?

The main prerequisites are Python 3 and the corresponding package manager (apt, yum, etc.).

3. How do I install a specific version of Ansible using pip?

You can specify the version number during installation with pip: pip install ansible==2.10.7

4. Can I run Ansible from a Docker container on Windows?

Yes, you can run Ansible inside a Docker container on Windows.

About Hitesh Jethva

I am Hitesh Jethva, Founder and Author at Code2DevOps.com. With over 15 years of experience in DevOps and open source technologies, I am passionate about empowering teams through automation, continuous integration, and scalable solutions.

View all posts by Hitesh Jethva