How to setup Homebrew on Mac OS

Patrick Rottländer
5 min readMar 15, 2021

Most of the Mac OS users install software via the Apple App store or download a .dmg file from the Internet and and copy the app into the Applications directory or run an installation script to install the software on the Mac. Another way to install software on your Mac is using a package manager like Homebrew. Homebrew is very easy to use and you have access to a large number of free software packages from developers around the world.

Homebrew Installation and Uninstallation

First check if Homebrew is (already) installed.

The above output show Homebrew 3.0.5.

In case Homebrew is not installed first check the requirements for Mac OS on the Homebrew Installation site. Here you find that Homebrew requires Command Line Tools (CLT) for Xcode. Therefore I first check if Command Line Tools are installed on my Mac.

The above command return that Command Line Tools for xcode (CLT) are installed on my Mac and show the path where the Command Line Tools are installed.

In case Command Line Tools for xcode are not installed run the following command before you start with the Homebrew installation.

:$ xcode-select --install

Then go to the Homebrew Website and check the actual installation instructions. At the time of writing this document you run the following script to install Homebrew.

:$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After the installation I check the Homebrew version and run brew doctor.

The shell output show that Homebrew version 3.0.5 is installed on the system and that I am ready to brew which means that I am now ready to install software with Homebrew.

To uninstall Homebrew you run the following script.

:$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

Update Command Line Tools for xcode

Homebrew need Command Line Tools for xcode but sometimes Command Line Tools can be outdated. When you run brew doctor and see the following message that Command Line Tools are outdated you must ensure that the latest version of Command Line Tools is installed on your Mac.

To update Command Line Tools for xcode they must first be uninstalled and then re- installed on the system. Pls. find additional information how to uninstall Command Line Tools for xcode and check the related Apple Developer Docs.

Homebrew Software Repositories and Tap(s)

With Homebrew package manager you have access to a wide range of software that can be installed on your system. After Homebrew has been installed on your system you find Homebrew under /usr/local/Homebrew on your system.

Homebrew differentiates between Core Software Packages and Cask Software or so-called Casks. All Software Packages are available in GitHub Repositories.

Homebrew Core Software Packages are free software developed from developers around the world to be installed on Mac OS platforms using Homebrew. Core software will be installed based on so called formulae. A formula contain the required information for the installation such as i.e. from where the installation files should be loaded, which dependencies exist and how the installation should be performed on the different Mac platforms. All formulae for Core Software Packages have been loaded from Homebrew’s GitHub Core-Repository Homebrew/homebrew-core into the core Tap on your machine. This Tap can be found on you machine in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core.

Homebrew Cask Software Packages are native Mac OS Apps like Google Chrome, Firefox or other Mac OS Apps that can be installed using the Homebrew Cask extension of the Homebrew Package Manager instead of installing the software via the Apple App Store or drag and drop a dmg file into the Application folder. How to use Homebrew Cask can be read on the Homebrew Cask GitHub site. Casks will be loaded from the Homebrew’s GitHub Cask-Repository Homebrew/homebrew-cask into the cask Tap on your machine. This Tap can be found on you machine in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask.

It is also possible to install Software that is not available on Homebrew’s GitHub Core-Repository or Homebrew’s GitHub Cask-Repository. In this case you must first tap the GitHub Repository to let Homebrew know, from where it should load the formula or cask to install the software package.

For example the formula for MongoDB has been removed from the GitHub Core-Repository. But fortunately the MongoDB Team is maintaining a custom GitHub-Repository mongodb/homebrew-brew from where you can tap the formulae on your local machine.

:$ brew tap mongodb/homebrew-brew

On GitHub, a Homebrew repository must be named homebrew-<something> in order to use the form of the brew tap with only one argument. When you use brew tap you can leave out the homebrew- prefix.

:$ brew tap mongodb/brew

This brew tap <username>/brew be used as a shortcut for the long version brew tap <username>/homebrew-brew. Homebrew will automatically add back the homebrew- prefix whenever it’s necessary.

The command brew tap without any arguments lists the GitHub repositories that are currently tapped on your local machine and available to install software from these sources.

Where are Packages on your System

Homebrew create symlinks for each installed package in /usr/local/bin and usually point to the binary in /usr/local/Cellar/<package_name>/<version>/bin. This is the standard. Depending on the definitions in the formula of a certain package the binaries can be also linked somewhere else on your system.

The Homebrew binary link named brew point to /usr/local/Homebrew/bin/brew. Any other binary link point into the Cellar in /usr/local/Cellar/<package_name>/<version>/bin. The Cellar is the place on your system where you usually find Homebrew installed software packages. As you see on my system I have installed a couple of software packages like boost, cmake and node.

Cask software is installed in the following directory.

Homebrew Cask create a symlink in /usr/local/Caskroom/<package_name>/<version>/<symlink> and point it to the app in the Applications directory where the app will be copied.

Install, Uninstall and Update Software Packages

To install a package using the brew install command.

:$ brew install <formula>

To uninstall a package using the brew uninstall command.

:$ brew uninstall <formula>

To update and upgrade all packages with Homebrew use the following commands.

:$ brew update:$ brew upgrade

You can also update and upgrade only a certain package.

:$ brew update <formula>:$ brew upgrade <formula>

The update command load the new formulae and the upgrade command installs the newer software versions in the Cellar. Depending on the amount of packages you have installed this might take some time.

When you install Cask Software the app must be copied into your Applications Directory. Here you need to provide your user password.

You can list the Casks installed on your Mac.

You can search for packages.

You install a cask package using the brew install command.

:$ brew install <cask-package>

You uninstall a cask package using the brew uninstall command.

--

--

Patrick Rottländer

I am a Node.js, Express.js, JavaScript, Python Webdeveloper, Author and Tech-Blogger on https://digitaldocblog.com