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 ansiblepipx (isolated, system-wide)
# Install pipx first if needed
pip install pipx
pipx ensurepath
# Install Ansible
pipx install ansiblepip (user install)
python3 -m pip install --user ansibleVerify:
ansible --versionMethod 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 ansibleSee also: How to Upgrade Ansible on macOS Using Homebrew
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 ansibleMethod 4: Fedora (dnf)
sudo dnf install ansibleSee also: Install Ansible on macOS: Homebrew & pip Installation Guide
Method 5: macOS (Homebrew)
brew install ansibleOr with pip:
pip3 install ansibleMethod 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 ansibleAnsible 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 |
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 package2. Create Inventory
mkdir ~/ansible && cat > ~/ansible/hosts << 'EOF'
[local]
localhost ansible_connection=local
[servers]
server1.example.com
server2.example.com
EOF3. Test Connection
ansible localhost -m ping
ansible servers -m ping -i ~/ansible/hosts4. 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.ymlUpgrade 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 ansibleInstall Specific Version
pip install ansible==10.0.0
pip install ansible-core==2.17.0Troubleshooting
"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 ansiblePython 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 ansibleFAQ
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 Guide
- Getting Started with Ansible
- Ansible Inventory: Complete Guide
- ansible.cfg Configuration File Guide
Enterprise and Specialized Platforms
Category: installation