Install Ansible on Mac
Last Updated:
Introduction
The best and fastest way to get started on macOS is to use Homebrew.
Installing Homebrew (if you haven't)
Install it via walkthrough by running this command in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
More details at: https://brew.sh
Updating $PATH
Checking Existing $PATH
Run the following command to see your current $PATH environment variable. You'll see output similar to mine below. If your output is slightly different, that's ok.
echo $PATH;
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
Make a note of the output, in case something goes wrong during the installation. Unlikely, but it can happen.
Macs with an Intel CPU
If your Mac has an Intel CPU, you can ignore this next section and go to Installing Ansible via Homebrew
Macs with the Apple M1 CPU
Update your $PATH environment variable with the following command.
# Sets Homebrew Variables for ZShell
# (default shell on macOS)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile;
# Sets Homebrew Variables for Bash
# (may be used in legacy applications)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bashrc;
# This updates your current Terminal shell session with the new environment variables.
# If you skip this, be sure to close any open Terminal windows and re-open new ones.
eval "$(/opt/homebrew/bin/brew shellenv)";
Your $PATH variable should now include "/opt/homebrew" entries near the beginning.
echo $PATH;
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
Installing Ansible via Homebrew
This is for all versions of macOS, once you've installed Homebrew above. Run the following command and you're done!
brew update; brew install ansible;
Checking Ansible Version
Ensure Ansible has been installed correctly and see its version number with the command below.
ansible --version;
ansible [core 2.12.4]
[... more info ...]
That's it! You're all set to begin using Ansible.