Install Ansible on Ubuntu: Complete Guide (22.04, 24.04, 26.04 LTS)
By Luca Berton · Published 2024-01-01 · Category: installation
How to install Ansible on Ubuntu 22.04, 24.04, and 26.04 LTS. Step-by-step installation via apt PPA, pip, and pipx.
Install Ansible on Ubuntu: Complete Guide (22.04, 24.04, 26.04 LTS)
This guide covers every method to install Ansible on Ubuntu, from the quick apt install to the recommended pip/pipx approach for the latest version. Works for Ubuntu 22.04 Jammy, 24.04 Noble, 25.10, and 26.04 LTS.
See also: Install Ansible: Complete Guide for Every OS (Ubuntu, RHEL, macOS, pip)
Quick Install (apt — Fastest Method)
sudo apt update
sudo apt install -y ansible
Check the installed version:
ansible --version
Note: The apt repository version may be older than the latest release. For the newest Ansible version, use pip or the PPA method below.
Method 1: Install via PPA (Recommended for apt Users)
The official Ansible PPA provides newer versions than the default Ubuntu repository:
# Add Ansible PPA
sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
# Install Ansible
sudo apt install -y ansible
Verify the installation:
ansible --version
ansible-community --version
See also: How to install Ansible in Ubuntu 20.04 - Ansible install
Method 2: Install via pip (Recommended for Latest Version)
pip gives you the latest Ansible release and better version control:
# Install pip if not present
sudo apt update
sudo apt install -y python3-pip python3-venv
# Install Ansible via pip (user install)
python3 -m pip install --user ansible
# Or install in a virtual environment (cleanest approach)
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate
pip install ansible
Install a Specific Version
pip install ansible==10.0.0
pip install ansible-core==2.17.0
Upgrade to Latest Version
pip install --upgrade ansible
Method 3: Install via pipx (Isolated Environment)
pipx installs Ansible in an isolated environment — cleanest option for system-wide use:
# Install pipx
sudo apt update
sudo apt install -y pipx
pipx ensurepath
# Install Ansible
pipx install ansible
# Or install with specific extras
pipx install ansible --include-deps
See also: How to install Ansible in Ubuntu 21.10 - Ansible install
Method 4: Install ansible-core Only (Minimal)
If you only need core Ansible without bundled collections:
pip install ansible-core
This installs ansible-playbook, ansible-galaxy, and other core tools but without the 85+ bundled collections.
Post-Installation Setup
1. Configure Inventory
Create your first inventory file:
mkdir -p ~/ansible
cat > ~/ansible/inventory.ini << 'EOF'
[local]
localhost ansible_connection=local
[webservers]
web1.example.com
web2.example.com
[dbservers]
db1.example.com ansible_user=admin
EOF
2. Create ansible.cfg
cat > ~/ansible/ansible.cfg << 'EOF'
[defaults]
inventory = ~/ansible/inventory.ini
remote_user = ubuntu
host_key_checking = False
retry_files_enabled = False
[privilege_escalation]
become = True
become_method = sudo
become_ask_pass = False
EOF
3. Test the Connection
# Test local connection
ansible localhost -m ping
# Test remote connection
ansible webservers -m ping
# Run a simple command
ansible all -m shell -a "uname -a"
Expected output:
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
4. Set Up SSH Keys
# Generate SSH key (if you don't have one)
ssh-keygen -t ed25519 -C "ansible@control-node"
# Copy to remote hosts
ssh-copy-id ubuntu@web1.example.com
ssh-copy-id ubuntu@web2.example.com
Ubuntu Version-Specific Notes
Ubuntu 22.04 LTS (Jammy)
• Default apt: Ansible 2.10.x (old) • PPA: Latest stable release • Python 3.10 included • Recommended: Use PPA or pip for current versionUbuntu 24.04 LTS (Noble)
• Default apt: Ansible 9.x • Python 3.12 included • Note: Some pip installs may need--break-system-packages flag or use pipx/venv
# If pip complains about externally managed environment:
python3 -m pip install --user ansible --break-system-packages
# Or better, use pipx:
pipx install ansible
Ubuntu 26.04 LTS (Plucky)
• Default apt: Ansible 10.x • Python 3.13 included • Recommended: pipx for clean installationInstall Ansible Collections
After installing Ansible, you may need additional collections:
# Install popular collections
ansible-galaxy collection install community.general
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.postgresql
# Install from requirements file
cat > requirements.yml << 'EOF'
collections:
- name: community.general
- name: ansible.posix
- name: amazon.aws
- name: community.docker
EOF
ansible-galaxy collection install -r requirements.yml
Troubleshooting
"ansible: command not found"
# Check if ansible is in PATH
which ansible
python3 -m pip show ansible | grep Location
# Add pip user bin to PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
"No module named 'ansible'"
# Reinstall with pip
python3 -m pip install --user ansible --force-reinstall
"externally-managed-environment" error (Ubuntu 24.04+)
# Use pipx instead
pipx install ansible
# Or use a virtual environment
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate
pip install ansible
Permission denied on remote hosts
# Check SSH access
ssh ubuntu@remote-host
# Check sudo access
ansible remote-host -m shell -a "whoami" --become
Uninstall Ansible
# If installed via apt:
sudo apt remove --purge ansible
# If installed via pip:
pip uninstall ansible ansible-core
# If installed via pipx:
pipx uninstall ansible
FAQ
What is the best way to install Ansible on Ubuntu?
For most users, pipx install ansible or installing in a Python virtual environment gives the latest version with clean isolation. For simplicity, sudo apt install ansible works but may provide an older version.
Can I install Ansible without root on Ubuntu?
Yes. Use python3 -m pip install --user ansible to install in your home directory, or pipx install ansible which also doesn't require root. Only the apt method needs sudo.
What Python version does Ansible need on Ubuntu?
Ansible requires Python 3.10 or newer on the control node. Ubuntu 22.04+ includes Python 3.10+. For managed hosts, Python 3.6+ is sufficient.
Should I install ansible or ansible-core?
Install ansible (the full package) for most use cases — it includes ansible-core plus 85+ collections. Install ansible-core only if you want a minimal installation and will manage collections separately.
How do I update Ansible on Ubuntu?
For apt: sudo apt update && sudo apt upgrade ansible. For pip: pip install --upgrade ansible. For pipx: pipx upgrade ansible.
Conclusion
Install Ansible on Ubuntu with pipx for the cleanest setup, pip in a virtual environment for version control, or apt with the PPA for the latest stable release. After installation, create your inventory file, configure SSH keys, and test with ansible localhost -m ping.
Related Articles
• Install Ansible: Complete Guide for Every OS • Install Ansible on Debian 12 Bookworm • Install Ansible on macOS with Homebrew • ansible.cfg Configuration File Guide • Ansible Inventory File: Complete GuideCategory: installation