How to install Homebrew on macOS to use the brew package manager

Homebrew is an essential package manager for developers, sysadmins, and power users on macOS. Homebrew allows us to install the latest and updated version of popular applications, packages, and developer tools. Homebrew is the painless way to install required packages on your Mac. For instance, we can install PostgreSQL, Python, PHP, Bash, Nginx, Apache, and much more using brew command. This page explains how to install and use Homebrew on the macOS system to get missing packages. Homebrew installs the apps you need that Apple didn’t include in their base operating system or app store.

How to install Homebrew on macOS package manager

Naturally, you need a Mac. Requirements are as follows:

  • A 64-bit Intel CPU or Apple Silicon CPU
  • macOS Mojave (10.14) (or higher)
  • Command Line Tools (CLT) for Xcode
  • A Bourne-compatible shell for installation

Always install Homebrew in the following directory as per your CPU architecture:

  • /usr/local on macOS Intel
  • /opt/homebrew on macOS ARM (M1)

Open the Terminal application on your nacOS and then type the following commands.

Step 1 – Installing xcode

Xcode is Apple’s IDE for macOS. We can use Xcode to produce apps for macOS, iOS, iPadOS, watchOS, and tvOS. We need Xcode for Homebrew for installation and compiling apps. Type the following command at bash/zsh prompt:
xcode-select --install

Confirm Xcode installation:

The installation will begin and wait for some time:

After sometimes we will see the final confirmation:

Step 2 – Installing Homebrew on macOS

Now that we installed Xcode, it is time to grab the Homebrew installer shell script. Use the wget command or download a file with curl as follows:
curl -O
We can see and review source code using vim/emacs for security reasons:

Finally install Homebrew by setting up permission on script as follows:
chmod +x
## OR directly execute ##

When prompted, enter your sudo (account) password and press [RETURN]/[ENTER] to continue installation on macOS:

Wait for some time as will download many files from the Internet. It took two minutes on a 100Mbps FTTH connection. Here is the final confirmation regarding Homebrew installation on my MBP:

Step 4 – Installing homebrew on a Mac and turning off analytics

By default Homebrew collects information and send analytics to developers. If you want you can disable analytics as follows:
brew analytics off
## add to your shell startup ##

Once executed the following information is no longer collected:

  • Homebrew user agent
  • Google Analytics
  • Homebrew analytics tracking ID and user ID

Display the current state of Homebrew’s analytics:
brew analytics

Step 3 – Searching for application

The syntax is:

brew search {package}
brew search nginx
brew search bash

We will see available options:

==> Formulae
apm-bash-completion        bash-git-prompt            bashish
bash                       bash-preexec               calabash
bash-completion            bash-snippets              checkbashisms
bash-completion@2          bashdb                     dhall-bash

Want to see detailed information about package, run:

brew info {package}
brew info nginx
brew info bash

Sample outputs:

bash: stable 5.1.4 (bottled), HEAD
Bourne-Again SHell, a UNIX command interpreter
Not installed
License: GPL-3.0-or-later
==> Options
	Install HEAD version

Step 4 – Using brew to install or remove 3rd party applications

Let us install an updated version of bash on macOS. Type:

brew install {package}
brew install bash

Installing Homebrew on a Mac and bash package

Please note that we can stop ‘bash’ from being updated/upgraded as follows:
brew pin bash
To allow bash formulae to update again:
brew unpin bash
I often lock down programming languages such as PHP and Python to continue on a specific version. Hence, I thought it is crucial to mention the pin/unpin option.

Step 5 – Update all your installed apps with brew

First update the formulae and Homebrew itself:
brew update
List outdated packages/formulae:
brew outdated
Now, all you have to do is type the following command and it will upgrade all installed formulas/packages:
brew upgrade

Step 6 – Say hello to Homebrew casks

On Mac, we use Homebrew Cask to installs macOS apps, fonts and plugins, and other non-open source software collections. Search for casks:
brew search --casks {keyword}
brew search --casks google
brew search --casks docker
brew search --casks aws

Let us install google-chrome, dropbox, and docker:
brew install --cask {package}
brew install --cask dropbox google-chrome docker

Step 7 – Reclaiming your disk space

We can remove stale lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae. This will free up disk space on your Mac for sure:
brew cleanup
brew cask cleanup

See “How to remove all old and outdated brew packages on MacOS” for more info.

Step 8 – Uninstalling Homebrew if the need arises

To uninstall Homebrew, run the uninstall script from the Homebrew/install repository as follows:
curl -O
bash --help

Quick help:

Usage: [options]
    -p, --path=PATH  Sets Homebrew prefix. Defaults to /usr/local.
                     Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
    -f, --force      Uninstall without prompting.
    -q, --quiet      Suppress all output.
    -n, --dry-run    Simulate uninstall but don't remove anything.
    -h, --help       Display this message.

Summing up

See Homebrew documentation online or type the following command:
man brew

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • tttvvvmmm Jan 22, 2021 @ 18:43

    FYI, wget command is not installed on macOS by default. Hence, we always end up using curl.

  • Mika Jan 23, 2021 @ 7:34

    These days I like MacPorts. May I suggest macports tutorial too?

  • Vaidya Feb 19, 2021 @ 7:21

    Excellent page. I got an Intel baed Macbook air for school and light video editing for my YouTube and this page was so useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @