A Beginner’s Guide to Homebrew

Every programmer on a Mac should know this package manager

Kenneth Worden
5 min readDec 27, 2018
The Homebrew logo. Credit brew.sh

Chances if you are a developer or tinkerer and you run macOS, you install tons of software.

Libraries, virtual machines, server software, version control, build systems, language compilers, fixes.

Installing software on a Mac typically involves dragging an application icon to the Applications folder. Easy peasy lemon squeezy, no?

No. What about the configuration files the application generates? You configure something, and now the application is broken. If you want to uninstall the application later, now you have delinquent data files and folders scattered on your hard-drive. This eats up precious hard-drive space- gigabytes if you are not careful.

Wouldn’t it be nice if there were something to keep track of all of this, making installing and uninstalling software a surgical procedure, rather than a patch job? Turns out there is!

Meet Homebrew

“The missing package manager for macOS”

Homebrew prides itself as “the missing package manage for macOS”. If you have ever used Ubuntu or a Debian-based linux installation, you might be familiar with apt-get, aptitude, or dpkg. These are all very powerful package managers that allow you to control every piece of software on your system. Homebrew attempts to capture the functionality of these managers. It manages packages locally on your machine and can download packages from online sources as well.

At first you may find yourself confused, mainly because Homebrew boasts a cheeky vernacular when it comes to describing software. You need not learn every term, but knowing a few will help:

Tap: A Git repository of packages. Typically, you will find Homebrew has the homebrew/core tap already “tapped”, meaning that you can install packages from this source.

Cellar: Where your local packages are installed by Homebrew. A cellar exists only on your local machine.

Formula: A software package. When we want to install new programs or libraries, we install a formula. Homebrew keeps multiple versions of formula (formulae) in the Cellar, so that you can downgrade if a new version of a package breaks something.

You can find all of the definitions here.

So, tap = repository, cellar = local install location, formula = software package. Got it? Good.

Installing Homebrew

Installing Homebrew is simple. Simply open a terminal and run:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

As defined on the Homebrew homepage. This command will always get you the latest version. Now that we are installed, let’s check out how to actually use it!

Using Homebrew

Finding packages (formulae) to install

To find packages to install, you can run:

$ brew search <name>

Although in today’s world, a quick Google search for “<package name> homebrew” can usually find you what you are looking for.

Once we find the package we want to install, we need to install it.

Installing formulae

The most common use of Homebrew is installing packages. Say we want to install Node.js on our machine. We need only do the following:

$ brew install node

This searches all of the taps (repositories) that you have configured Homebrew with, and finds a matching formula (package) with the provided name. Node is located in the default core tap. However, sometimes you may not be able to find the formula you want.

In this case, you need to add a new tap.

Adding taps (repositories)

If Homebrew cannot find the package you want, it may be hosted in a different repository. As mentioned before, homebrew/core is already “tapped” (Homebrew searches this repository) for you. To view what is already tapped, simply run:

$ brew tap

Your output may look like this:

homebrew/cask
homebrew/core

But what does homebrew/core mean? Why is there a slash?

By default, Homebrew assumes that you are looking for a repository on Github. The convention for tap names is <user>/<repo>. That means that there is a Github user, homebrew, with a repository, core. And so there is.

Because this is a Homebrew special repository that is tapped by default, the repo is actually called homebrew-core. Note that the <user>/<repo> form is a convention, not a strict requirement.

To actually add new taps, use one of the following commands:

$ brew tap <user>/<repo>

This command assumes that the repository is hosted on Github, and is a shorthand. If you want to tap repositories hosted elsewhere, use:

$ brew tap <user>/<repo> <URL>

The <URL> argument specifies the clone URL. The <user>/<repo> form thus denotes how we refer to this tap in the future- you can call it whatever you want.

After tapping a new repository, you can install whatever formula you were trying to before. To find new repositories, again, a quick Google search will usually yield the answer.

Homebrew keeps a list of packages and their versions in a local cache. Obviously, if you do not use Homebrew for a few weeks, this cache will be outdated and may cause you to install outdated software. To correct this, we can keep our taps fresh.

Keeping taps fresh

Before running brew install, it is best to get the latest versions of formulae so you do not accidentally install an old package version. This is simple:

$ brew update

Now installing packages will get you the latest version, which is typically what you want.

Homebrew will typically keep itself up-to-date when you run other brew commands, but calling this is still a good practice.

Upgrading local packages

Software moves fast. Packages get updated frequently- thehomebrew/core tap was updated 16 minutes ago as of my writing this. To upgrade installed formulae, simply run:

$ brew upgrade

This takes all of the formulae you have installed, checks their respective taps for new versions, and installs the new versions for you automatically. Typically, you will want to brew update right beforehand:

$ brew update && brew upgrade

This keeps you from upgrading to the non-latest versions of packages.

So brew update gets the latest versions of packages and brew upgrade installs the latest versions.

Removing formulae

Say you want to uninstall a package. This is self-explanatory:

$ brew uninstall <formula>

For example:

$ brew uninstall node

However, say you upgraded this package a few times. Homebrew keeps old versions of packages, and thus you might have a few Node.js binary versions in your Cellar. If you find yourself strapped for hard-drive space, run:

$ brew uninstall -f node

This tells Homebrew to uninstall all versions of the node package.

Reducing clutter

To remove old versions of packages and free up space, you can run:

$ brew cleanup

This cleans up old versions, lock files, and outdated files, keeping your hard-drive squeaky clean!

Conclusion

Although Homebrew introduces nomenclature that can be off-putting to the beginner, it is a capable software that has earned its place as the de facto package manager in the macOS system.

This tutorial walked us through how to install and use Homebrew to manage software on our Macs. Hopefully this helped you! If it did, remember to clap it up!

Thanks for reading! Peace ✌✌✌

--

--