Last Updated on 2 days by Sachin G

Ansible is one of the most popular automation tools for Linux system administrators and DevOps engineers. Whether you’re deploying applications, managing configurations, or orchestrating IT infrastructure, installing Ansible on CentOS, RHEL, AlmaLinux, or Rocky Linux is often the first step toward streamlining your workflow.

If you’re completely new to Ansible, I’ve already covered the basics—including what Ansible is, how it works, and why it’s essential—in our article From Sysadmin to DevOps: Introduction to Ansible. You may want to start there before diving into installation, so you’ll have a clear understanding of the core concepts before getting hands-on.

In this guide, we’ll walk you through:

  • Installing Ansible on different RHEL-based systems.
  • Multiple methods, including Yum/DNF, EPEL repository, and offline installation.
  • How to install specific Ansible versions for compatibility.
  • Best practices and real-world tips from production environments.

Prerequisites

Before you start, ensure:

  • You have root or sudo access.
  • Your system is connected to the internet (unless using the offline method).
  • Your system package manager is Yum (CentOS/RHEL) or DNF (AlmaLinux/Rocky).

Method 1: Install Ansible on CentOS/RHEL using Yum

This is the simplest and most recommended method for CentOS 8 Stream and CentOS 9 Stream.

sudo yum install epel-release -y
Install EPEL repository on CentOS or RHEL using yum command.
Screenshot by TechTransit.org: Installing the EPEL repository to enable access to extra Ansible packages.
  • EPEL stands for Extra Packages for Enterprise Linux.
  • This repository contains additional packages, including Ansible, that are not in the default RHEL/CentOS repositories.
  • This command downloads and installs the repository configuration file so your system knows where to get these extra packages.

The below command will install the Ansible package and all its dependencies from the enabled repositories (including EPEL).

sudo yum install ansible -y
Install Ansible on CentOS or RHEL using yum command.
Screenshot by TechTransit.org: Installing Ansible from the EPEL repository on a RHEL-based Linux distribution

Method 2: Install Ansible on AlmaLinux & Rocky Linux using DNF

For AlmaLinux 9 and Rocky Linux 9, DNF is the default package manager. dnf The next-generation version of yum (used in RHEL 8, CentOS 8, AlmaLinux, Rocky Linux).Works the same way as yum but with better performance and dependency resolution.

sudo dnf install epel-release -y
sudo dnf install ansible -y

Method 3: Install a Specific Version of Ansible

Sometimes you need an older Ansible version for compatibility (e.g., Ansible 2.9 on RHEL 8). In some environments, you may need a specific Ansible version for compatibility with older playbooks, CI/CD pipelines, or enterprise-approved configurations. While yum or dnf Sometimes allows version selection, many RHEL-based repositories only provide the latest version, making pip a better choice for version control.

Step 1: Install pip

If pip is not already installed, install it with:

sudo yum install python3-pip -y
Screenshot by TechTransit.org: Install Python 3 pip package manager on CentOS or RHEL

or on newer RHEL-like systems:

sudo dnf install python3-pip -y

This ensures you can install Python-based packages directly from PyPI.

Step 2: Install a Specific Ansible Version

Use pip to install the desired version:

pip3 install ansible==2.9.27

Replace 2.9.27 with the version you require.

Install a specific version of Ansible using pip on Linux.
Screenshot by TechTransit.org: Installing Ansible version 2.9.27 via pip for compatibility with older playbooks.

Method 4: Install Ansible Without Internet (Offline)

For air-gapped environments, download RPMs on a machine with internet access:

# Download Ansible RPM packages without installing them

yum install --downloadonly --downloaddir=ansible_pkgs ansible

# Compress the downloaded RPMs into a single tar.gz archive

tar -czvf ansible_pkgs.tar.gz ansible_pkgs
Download Ansible RPM packages without installing them
Screenshot by TechTransit.org: Download Ansible RPM packages without installing, saving them in the ansible_pkgs directory.
Screenshot by TechTransit.org : Showing only the download package, not the install by yum/dnf by download-only option

Transfer the archive to the offline server and run:

# Install Ansible from local RPM files (offline installation)

yum localinstall ansible_pkgs/*.rpm
Install Ansible from local RPM files (offline installation)
Screenshot by TechTransit.org: Install Ansible from local RPM files in an offline or air-gapped environment.

Verify Installation:

Checks if Ansible is installed and displays the installed version, configuration file location, and Python interpreter path.

ansible --version

Example output:

ansible [core 2.14.18]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.21 (main, Jun 27 2025, 00:00:00) GCC 11.5.0 20240719 (Red Hat 11.5.0-5)
jinja version = 3.1.2
libyaml = True

From working on Ansible Red Hat installation guide projects, I’ve learned:

“Always match your Ansible version with the environment’s requirements. Installing the latest version isn’t always the best choice for production stability.”

One common challenge is forgetting to enable the EPEL repository, which causes installation to fail with package not found errors.

FAQ – Installing Ansible on CentOS/RHEL-like OS

Q: How do I install Ansible on RHEL 8 without EPEL?

A: Use the Red Hat Automation Hub or enable the official Ansible Automation Platform repository.

Q: What’s the easiest way to install Ansible on AlmaLinux 9?

A: Use:
sudo dnf install epel-release -y && sudo dnf install ansible -y

Q: Can I use Pip to install Ansible?

A: Yes, but it’s better to use your distribution’s package manager for system-wide use.

Q: How do I install an older Ansible version?

A: Use:


sudo yum install ansible- -y

Q: Is Ansible available in the default RHEL repositories?


A: Not by default—you need EPEL or Red Hat’s official automation repositories.

Q: Is there a difference in installation between CentOS, AlmaLinux, and Rocky Linux?

A: The commands are almost identical—only the package manager name (Yum/DNF) changes.

Whether you are on CentOS, RHEL, AlmaLinux, or Rocky Linux, installing Ansible is straightforward with Yum/DNF. By following best practices—like using the correct repository and version—you can avoid common pitfalls.

Want to learn more about Ansible?
Please explore our complete Ansible Tutorials for Beginners to master automation step-by-step.
You can also check out our Recommended Ansible Courses for expert-led training and practical projects to boost your skills.