AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Install Ansible: Complete Guide for Every OS (Ubuntu, RHEL, macOS, pip)

By Luca Berton · Published 2024-01-01 · Category: installation

How to install Ansible on any operating system. Step-by-step installation on Ubuntu, Debian, RHEL, CentOS, Fedora, macOS, and Windows WSL.

Install Ansible: Complete Guide for Every OS (Ubuntu, RHEL, macOS, pip)

This guide covers how to install Ansible on every major operating system and distribution. Whether you're on Ubuntu, RHEL, macOS, or Windows WSL — pick your method and get started in minutes.

See also: Installing Ansible: A Step-by-Step Guide

Quick Install by OS

| OS | Fastest Command | |----|----------------| | Ubuntu/Debian | sudo apt install ansible | | RHEL/CentOS/Fedora | sudo dnf install ansible | | macOS | brew install ansible | | Any OS (pip) | pip install ansible | | Any OS (pipx) | pipx install ansible |

Method 1: pip / pipx (Any OS — Latest Version)

The recommended method for getting the latest Ansible version on any platform:

pip (in virtual environment)

python3 -m venv ~/ansible-env
source ~/ansible-env/bin/activate
pip install ansible

pipx (isolated, system-wide)

# Install pipx first if needed
pip install pipx
pipx ensurepath

# Install Ansible pipx install ansible

pip (user install)

python3 -m pip install --user ansible

Verify:

ansible --version

See also: How to Upgrade Ansible on macOS Using Homebrew

Method 2: Ubuntu / Debian (apt)

# Option A: Default repository
sudo apt update
sudo apt install -y ansible

# Option B: PPA (newer version) sudo apt install -y software-properties-common sudo add-apt-repository --yes --update ppa:ansible/ansible sudo apt install -y ansible

Method 3: RHEL / CentOS / Rocky / Alma (dnf/yum)

# RHEL 9 / CentOS Stream 9 / Rocky 9
sudo dnf install ansible-core

# For full Ansible package with collections: sudo dnf install python3-pip pip install ansible

# RHEL 8 (enable EPEL first) sudo dnf install epel-release sudo dnf install ansible

See also: Install Ansible on macOS: Homebrew & pip Installation Guide

Method 4: Fedora (dnf)

sudo dnf install ansible

Method 5: macOS (Homebrew)

brew install ansible

Or with pip:

pip3 install ansible

Method 6: Windows (WSL)

Ansible doesn't run natively on Windows — use Windows Subsystem for Linux:

# 1. Install WSL (PowerShell as admin)
wsl --install

# 2. Inside Ubuntu WSL: sudo apt update sudo apt install -y ansible

Ansible CAN manage Windows hosts from a Linux control node via WinRM.

Method 7: Docker

# Run Ansible in a container
docker run --rm -it -v $(pwd):/ansible \
  -v ~/.ssh:/root/.ssh:ro \
  alpine/ansible ansible-playbook /ansible/playbook.yml

# Or build your own docker run --rm -it python:3.12-slim sh -c "pip install ansible && ansible --version"

ansible vs ansible-core

| Package | Includes | Size | |---------|----------|------| | ansible | ansible-core + 85+ collections | ~150MB | | ansible-core | Core engine, built-in modules only | ~15MB |

For most users, install ansible. Install ansible-core only for minimal setups where you'll manage collections separately.

Post-Install: First Steps

1. Verify Installation

ansible --version
ansible-community --version  # Only if full ansible package

2. Create Inventory

mkdir ~/ansible && cat > ~/ansible/hosts << 'EOF'
[local]
localhost ansible_connection=local

[servers] server1.example.com server2.example.com EOF

3. Test Connection

ansible localhost -m ping
ansible servers -m ping -i ~/ansible/hosts

4. Run First Playbook

# ~/ansible/first-playbook.yml
---
- name: My first playbook
  hosts: localhost
  connection: local
  tasks:
    - name: Print hello
      ansible.builtin.debug:
        msg: "Ansible is working! Version: {{ ansible_version.full }}"
ansible-playbook ~/ansible/first-playbook.yml

Upgrade Ansible

# pip
pip install --upgrade ansible

# pipx pipx upgrade ansible

# apt (Ubuntu) sudo apt update && sudo apt upgrade ansible

# dnf (RHEL/Fedora) sudo dnf upgrade ansible

# Homebrew (macOS) brew upgrade ansible

Install Specific Version

pip install ansible==10.0.0
pip install ansible-core==2.17.0

Troubleshooting

"command not found" after pip install

# Add pip bin to PATH
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

"externally-managed-environment" (Ubuntu 24.04+)

# Use pipx or venv instead
pipx install ansible
# or
python3 -m venv ~/ansible-env && source ~/ansible-env/bin/activate && pip install ansible

Python version issues

Ansible requires Python 3.10+ on the control node:

python3 --version
# If too old, install newer Python:
sudo apt install python3.12
python3.12 -m pip install ansible

FAQ

What is the easiest way to install Ansible?

On Ubuntu: sudo apt install ansible. On macOS: brew install ansible. For the latest version on any OS: pipx install ansible or pip install ansible in a virtual environment.

Can I install Ansible on Windows?

Not natively. Install WSL (Windows Subsystem for Linux) first, then install Ansible inside the Linux environment. Ansible can manage Windows hosts remotely via WinRM from a Linux control node.

Should I install Ansible with pip or apt?

Use pip (or pipx) for the latest version and better version control. Use apt/dnf for simpler installation that integrates with OS package management. For production, pip in a virtual environment is recommended.

What Python version does Ansible require?

Ansible control node requires Python 3.10+. Managed (remote) hosts need Python 3.6+ for most modules. The raw and script modules work without Python on remote hosts.

How do I install Ansible collections after installation?

Use ansible-galaxy collection install collection_name. For example: ansible-galaxy collection install community.general. Define project dependencies in requirements.yml and install with ansible-galaxy collection install -r requirements.yml.

Conclusion

Install Ansible with pipx for the cleanest experience, pip in a venv for version control, or your OS package manager for simplicity. After installation, create an inventory file, test with ansible localhost -m ping, and run your first playbook.

Related Articles

Install Ansible on Ubuntu: Complete GuideGetting Started with AnsibleAnsible Inventory: Complete Guideansible.cfg Configuration File Guide

Enterprise and Specialized Platforms

Ansible on AIX 7.3 Automation Complete GuideAnsible on IBM i 7.5 Automation Complete GuideAnsible on Nutanix AHV Automation Complete GuideAnsible on z/OS 3.1 Automation Complete Guide

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home