
Homebrew
The first installation method is to use a package called Homebrew.
Homebrew is a package manager of macOS. It can be used to install command-line tools and also desktop packages. It describes itself as The missing package manager for macOS and it is normally one of the first tools I install after a clean installation or when getting a new computer. You can find out more about the project at https://brew.sh/.
To install Ansible using Homebrew, you first need to install Homebrew. To do this, run the following command:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
At each step of the installation process, the installer will tell you exactly what it is going to do and also prompt you for any additional information it needs from you in order to complete the installation.
Once installed, or if you already have Homebrew installed, run the following commands to update your list of packages and also check that your Homebrew installation is optimal:
$ brew update
$ brew doctor
Depending on how new your installation is, or when you last used it, you might see a different output to the following screenshot:

Next, we can check what packages Homebrew provides for Ansible by running the following command:
$ brew search ansible
As you can see from the results in the following screenshot, there are several packages returned in the search:

We just want the Ansible package. You can find out more about the package by running the following command:
$ brew info ansible
You can see the results of the command in the following screenshot:

As you can see, the command returns information on the version of the package that will be installed, as well as details on where you can see the code for the formula that installs the package. In our case, you can view details of the formula at https://github.com/Homebrew/homebrew-core/blob/master/Formula/ansible.rb.
To install Ansible using Homebrew, we simply have to run the following command:
$ brew install ansible
This will download and install all of the dependencies and then the Ansible package itself. Depending on how much of the dependencies are already installed on your machine, this may take a few minutes. Once installed, you should see something like the following screenshot:

As you can see from the preceding screenshot, Homebrew is quite verbose in its output, giving you both feedback on what it is doing and details on how to use the packages it installs.