---
title: How to Install Ansible (Ubuntu, RHEL, CentOS, macOS)
description: Learn how to download Ansible, install Ansible on Ubuntu, install Ansible on a Mac and install on RHEL/CentOS in this step-by-step guide!
canonical: https://adamtheautomator.com/install-ansible/
---

# How to Install Ansible (Ubuntu, RHEL, CentOS, macOS)

> Learn how to download Ansible, install Ansible on Ubuntu, install Ansible on a Mac and install on RHEL/CentOS in this step-by-step guide!

Source: https://adamtheautomator.com/install-ansible/

---

- How to Install Ansible (Ubuntu, RHEL, CentOS, macOS) Tap to hide Home

- Tutorials

- Guidebooks

- Instructors

- Get Paid to Write

- Advertising

- Recommended Resources

- About Adam

                Search for:

-

-

-

-

# How to Install Ansible (Ubuntu, RHEL, CentOS, macOS)

        Published:27 April 2021 - 4 min. read

- Ansible

          [](https://adamtheautomator.com/author/shanky-mendiratta/)

            [Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)

            Read [more tutorials](https://adamtheautomator.com/author/shanky-mendiratta/) by Sagar!

-

-

        [](https://specopssoft.com/product/specops-password-auditor/?utm_source=adamtheautomator&utm_medium=referral&utm_campaign=adamtheautomator_referral_na&utm_content=display)
        Audit Active Directory for stale users, weak passwords, and other security risks with [Specops Password Auditor](https://specopssoft.com/product/specops-password-auditor/?utm_source=adamtheautomator&utm_medium=referral&utm_campaign=adamtheautomator_referral_na&utm_content=text).

Table of Contents

- Installing Ansible on Ubuntu
- Installing Ansible on RHELInstalling Ansible on CentOS
- Installing Ansible on macOS
- Testing Out Ansible by Running Ad-Hoc Commands
- Conclusion

                XFacebookLinkedIn

If you've got many hosts to manage, it's time to automate configuration management by installing [Ansible](https://docs.ansible.com/ansible/latest/index.html)! Ansible is the most popular automation tool to manage configuration changes across your on-prem and cloud resources.

In this article, you're going to learn from the ground up how to download and install an Ansible controller host on Ubuntu, RHEL, and macOS. You'll also get a jump start on running your first commands!

This tutorial will use v2.9.20 of [Ansible](https://adamtheautomator.com/ansible-on-windows/)but the process to set up Ansible on a controller host should be near identical for later versions.

Let's get started!

Related:[A Step-by-Step Guide to Getting Started with Ansible on Windows](https://adamtheautomator.com/ansible-on-windows/)

## Installing Ansible on Ubuntu

You can install Ansible on any *nix-based operating system. One of the most popular choices out there is Ubuntu. Let's kick off this tutorial and go through a walkthrough on how to make it happen.

If you'd like to set up Ansible on Ubuntu, this section is going to assume you have an Ubuntu 18+ machine with [Python2 or higher installed](https://docs.python-guide.org/starting/install3/linux/). This tutorial will be using Ubuntu 18.04.5 LTS with Python3.

1. Connect to your soon-to-be Ansible controller on an Ubuntu host with your favorite SSH client.

2. Ansible is stored as a package that can be downloaded and installed via the apt package manager. To ensure apt can find the proper source and download any dependent packages run [apt update](https://www.cyberciti.biz/faq/what-does-sudo-apt-get-update-command-do-on-ubuntu-debian).

sudo apt update

The [apt or apt-get](https://guide.ubuntu-fr.org/server/apt.html) command installs the packages from apt software repositories configured in Ubuntu.

3. Continue preparing apt to download and install Ansible by installing the [software-properties-common package](https://askubuntu.com/questions/1000118/what-is-software-properties-common). sudo apt install software-properties-common

sudo apt install software-properties-common

Installing the package using apt command

4. Next, add the ansible/ansible [personal package archive (PPA)](https://help.launchpad.net/Packaging/PPA) as an apt repository. This repository is managed by Red Hat, not by Ubuntu sources, so you must add it manually.

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

Addition of ansible PPA repository

5. Now, install the ansible package by running the apt install command

sudo apt install ansible

6. When complete, confirm Ansible is installed by running the ansible --version command. If all is well ansible --version

ansible --version

Checking the Ansible version

## Installing Ansible on RHEL

Ubuntu isn't the only operating system Ansible supports. [Red Hat Enterprise Linux (RHEL)](https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux) or [CentOS](https://www.centos.org/) are also common options. Let's start with RHEL.

If you plan to follow this section, ensure you have an RHEL release 8+ host (this tutorial will use RHEL 8.3 (Ootpa).

1. Connect to your RHEL host via SSH with your favorite SSH client.

2. Install the python3-pip and python3 package with [dnf](https://developers.redhat.com/blog/2016/08/30/why-red-hats-new-dnf-package-manager-is-not-just-another-yum-2). Ansible works with Python2, but this tutorial will be using Python3 because Python2 is soon to be considered legacy.

sudo dnf install python3 python3-pip -y

Installing the python3 and python3-pip

3. Install the [Extra Packages for Enterprise Linux (EPEL) repository](https://docs.fedoraproject.org/en-US/epel/). The EPEL repository contains various system packages including the Ansible package which you will install in the next step.

sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Addition of EPEL repository

4. Once you've installed the repository, install the Ansible package by referencing the required EPEL repository and the package's name (ansible). The dnf utility will automatically download the latest version of Ansible.

sudo dnf install  --enablerepo epel-playground  ansible

5. Now, check to ensure Ansible has been installed successfully by running

Checking the Ansible version

### Installing Ansible on CentOS

Rounding out the *nix hosts, let's end with setting up Ansible on CentOS.

If you plan to follow this section, ensure you have a CentOS 7+ host with Python2 or higher installed (this tutorial will use CentOS 7.9.2009 Core).

1. Connect to your CentOS host via SSH with your favorite SSH client.

2. Install the [Extra Packages for Enterprise Linux (EPEL) repository](https://docs.fedoraproject.org/en-US/epel/). The EPEL repository contains various system packages, including the Ansible package, which you will install in the next step.

# Installing the epel-release package using the yum command yum install epel-release
yum install epel-release

The [yum command](https://access.redhat.com/solutions/9934) installs and manages software by using the official Red Hat software repositories, as well as other third-party repositories.

Installing the epel-release package using the yum command

3. Once the repository is complete, install the Ansible package.

sudo yum install ansible

Installation of Ansible package

4. Now, confirm Ansible is installed by running ansible --version.

Checking the Ansible Version

## Installing Ansible on macOS

So far, you have learned how to set up Ansible on various Linux distros. Let's finish out this tutorial by learning how to install Ansible on a Mac.

This section of the tutorial will focus on the popular macOS package manager called [Homebrew](https://docs.brew.sh/Installation.html). Homebrew is the easiest way to install Ansible on macOS. This tutorial will be using Homebrew v3.0.7 on macOS Catalina.

If you'd like to learn how to install Ansible via the popular Python package manager pip, check out the [Ansible pip package](https://pypi.org/project/ansible/).

To install on macOS:

- Open up the Apple Terminal.

- Run the following command to invoke Homebrew to download and install Ansible on your Mac.

brew install ansible

- Once complete, verify Ansible is installed by running ansible --version.

$ ansible --version
ansible 2.7.5
  config file = None
  configured module search path = ['/Users/shanky/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.7.5/libexec/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.2 (default, April 13 2021, 07:35:52) [Clang 10.0.0 (clang-1000.11.45.5)]

## Testing Out Ansible by Running Ad-Hoc Commands

Now that Ansible is installed, it's not doing much good unless you actually use it! One of the easiest ways to get started with Ansible is to learn about [ad hoc](https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html) commands. Ad hoc commands are one-off usually single-line commands that the Ansible invokes on remote computers (or on the Ansible host in this example).

Related:[Running ad-hoc Commands on Windows Hosts](https://adamtheautomator.com/ansible-on-windows/)

Run an ad-hoc command on your operating system of choice by using the -m switch. The -m switch specifies an [Ansible module](https://docs.ansible.com/ansible/latest/user_guide/modules.html) that contains various functionality.

One of the simplest Ansible modules is the [ping module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ping_module.html). This module tests connectivity between the Ansible controller and a host. If you don't have any remote hosts available, provide the name of the Ansible controller itself (localhost) to run the ping module against.

ansible localhost  -m ping

If successful, you should see green output indicating success!

Running the ansible ad hoc ping module

## Conclusion

In this tutorial, you learned how to set up the most widely used automation tool, Ansible, on Ubuntu, RHEL, CentOS, and macOS.

Now that you have a new Ansible controller host set up, what do you plan to manage with it?

  Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

  [Explore ATA Guidebooks](https://adamtheautomator.com/ata-guidebooks/)

## More from ATA Learning and Partners

- ### Recommended Resources! Recommended Resources for Training, Information Security, Automation, and more!

- ### Get Paid to Write! ATA Learning is always seeking instructors of all experience levels. Regardless if you’re a junior admin or system architect, you have something to share. Why not write on a platform with an existing audience and share your knowledge with the world?

- ### ATA Learning Guidebooks ATA Learning is known for its high-quality written tutorials in the form of blog posts. Support ATA Learning with ATA Guidebook PDF eBooks available offline and with no ads!

## Categories

- IT Ops

- Cloud

- DevOps

- Home Ops

- Information Security

- Software Development

## Site

- Home

- Tutorials

- Guidebooks

- Instructors

- Get Paid to Write

- Advertising

- Recommended Resources

- About Adam

        Copyright 2026&copy; ATA Learning | [Privacy Policy](https://adamtheautomator.com/privacy/)

                                                        Don't be left behind with the ATA Learning Newsletter!

Looks like you're offline!
