---
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/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Install Ansible (Ubuntu, RHEL, CentOS, macOS)](https://adamtheautomator.com/wp-content/uploads/2021/04/How-to-Install-and-Setup-Ansible-Controller-Host-on-Various-Operating-Systems.jpg)

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

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)27 April 20214 min. read

Categories: [DevOps](/category/devops/)

Tags:[Ansible](/tag/ansible/)

Table of Contents

*   [Installing Ansible on Ubuntu](#h-installing-ansible-on-ubuntu)
*   [Installing Ansible on RHEL](#h-installing-ansible-on-rhel)
*   [Installing Ansible on CentOS](#h-installing-ansible-on-centos)
*   [Installing Ansible on macOS](#h-installing-ansible-on-macos)
*   [Testing Out Ansible by Running Ad-Hoc Commands](#h-testing-out-ansible-by-running-ad-hoc-commands)
*   [Conclusion](#h-conclusion)

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).

```bash
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`

```bash
sudo apt install software-properties-common
```

![Installing the package using apt command](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T174852.113.png)

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.

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

![Addition of ansible PPA repository](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175000.751.png)

Addition of ansible PPA repository

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

```bash
sudo apt install ansible
```

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

```bash
ansible --version
```

![Checking the Ansible version](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175128.409.png)

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.

```bash
sudo dnf install python3 python3-pip -y
```

![Installing the python3 and python3-pip](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175256.424.png)

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.

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

![Addition of EPEL repository](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175404.141.png)

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.

```bash
sudo dnf install  --enablerepo epel-playground  ansible
```

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

![Checking the Ansible version ](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175508.468.png)

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.

```bash
# 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](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175644.642.png)

Installing the epel-release package using the yum command

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

```bash
sudo yum install ansible
```

![ Installation of Ansible package](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175716.630.png)

Installation of Ansible package

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

![Checking the Ansible Version](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175754.265.png)

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:

1.  Open up the **[Apple Terminal](https://www.businessinsider.com/how-to-open-terminal-on-mac)**.
2.  Run the following command to invoke Homebrew to download and install Ansible on your Mac.

```bash
brew install ansible
```

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

```bash
$ 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.

```bash
ansible localhost  -m ping
```

If successful, you should see green output indicating success!

![Running the ansible ad hoc ping module](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-2021-04-25T175951.728.png)

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?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Finstall-ansible%2F&text=How%20to%20Install%20Ansible%20\(Ubuntu%2C%20RHEL%2C%20CentOS%2C%20macOS\))[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Finstall-ansible%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Finstall-ansible%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2021/04/A-Step-by-Step-Guide-to-Getting-Started-with-Ansible-on-Windows.jpg)

### [Mastering Ansible on Windows: Your Go-To Expert Guide](/ansible-on-windows/)

Ansible on Windows made simple. A complete guide to hassle-free installation and configuration, perfect for users seeking quick and effective mastery.

![](https://adamtheautomator.com/wp-content/uploads/2022/10/How-to-Manage-Python-Libraries-with-Ansible-Pip.jpg)

### [How to Manage Python Libraries with Ansible Pip](/ansible-pip/)

Learn how to effectively manage Python libraries with the Ansible Pip module and take control of your Python dependencies!

![](https://adamtheautomator.com/wp-content/uploads/2022/06/Highly-Effective-Automation-with-Ansible-AWX.jpg)

### [Highly Effective Automation with Ansible AWX](/ansible-awx/)

Learn how Ansible AWX can take your Ansible playbooks to the next level and automate all the things with this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
