Using Homebrew with a minimum of fuss

Command Line – Homebrew

© Photo by Adam Wilson on Unsplash

© Photo by Adam Wilson on Unsplash

Article from Issue 262/2022

Homebrew, a comprehensive package manager, has been increasing in popularity thanks to its ease of use.

Linux has no shortage of package managers. Besides basic ones such as RPM, DNF, and dpkg/apt-get/APT, there are supposedly universal ones such as Flatpak and Snap, and increasingly, one for each programming language. Originating in macOS and formerly called Linuxbrew on Linux, Homebrew [1] is especially popular in the Ruby on Rails community. Recently, however, it has started gaining a larger popularity due to its ease of use. If you want to install anything from a project in early development, increasingly there is a good chance that you will need Homebrew to do so. Homebrew offers the option of non-root installation, access to developing software outside your distribution's repositories, and multiple versions of applications. In addition, if you maintain multiple operating systems, you can use the same package manager and set of commands on Linux, macOS, and the Windows Subsystem for Linux.

Homebrew installs files to /home/linuxbrew and symlinks them to /usr/local, so that you do not need to be root to use it. Before installing, make sure you have all the necessary packages by running the command

apt install build-essential procps curl file git

If you plan to run Homebrew from a regular user account, you will also need to set up the account to access sudo, because the installation script may ask for your sudo password. When you are ready, install Homebrew [2] [3] with:

/bin/bash -c "$(curl -fsSL"

When installation succeeds, you will see the message Installation successful, followed by additional instructions (Figure  1). These consist of adding Homebrew to your Bash path using the series of commands in Listing 1, run one at a time.

Listing 1

Adding Homebrew to Your Bash Path

test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)"
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -r ~/.bash_profile && echo "eval "$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile
echo "eval "$($(brew --prefix)/bin/brew shellenv)\" >> ~/.bash_profile
Figure 1: The start of Homebrew's installation script. Notice the assumption of sudo and the installation directory of /home/linuxbrew.

Because none of these commands offers any feedback, you can test that Homebrew is properly installed by running

homebrew install hello

and running the hello command. If Homebrew is not running, run brew update a couple of times and brew doctor to see if there are any obvious issues (Figure 2). If you still have problems, check the online list of common issues [4].

Figure 2: Homebrew formulae installs are "Pourings." Output is conveniently emphasized by arrows and progress bars for each step.

A Note on the Jargon

An annoying feature of Homebrew is that it extends the metaphor of its name, giving different names for its directories depending on their contents, such as cellar, rack, or kegs, making it hard to know how one term relates to another. Similarly, when installing, the output talks of "Pouring" (Figure 2). Fortunately, for many basic uses, you can ignore this needless complication, but Figure 3 shows how the various terms are related to each other. Mostly, you only need to know that a formula is a package, and a manifest is a package's installation script. These two pieces of jargon break the metaphor, but perhaps that comes as a relief. Occasionally, however, it may be quickest to work with multiple formulae by using, for instance, commands that affect kegs or racks (i.e., directories with multiple formulae). If you need to know more about other terminology, a summary is available online [5].

Figure 3: Homebrew has a complicated series of names that reflect the contents of each directory.

Using the brew Command

The basics of Homebrew are almost identical to those of most package managers. That is, they consist of the basic command, followed by a sub-command or action, and then the specific package affected, if any. Commands that do not specify a formula apply to all of Homebrew, such as brew autoremove. Table 1 shows a list of basic commands, using gcc as an example. This is, of course, a different version of gcc than any installed from a distribution's repositories. Like Debian and other distributions, Homebrew also maintains a web page of available formulae (one the same page as the Homebrew terminology [5].

Table 1

Basic Homebrew Commands




brew install gcc


brew remove gcc

Auto-remove dependencies

brew autoremove

Upgrade formula

brew upgrade gcc

Upgrade all formulae

brew upgrade

List installed formulae

brew list

List available formulae

brew formulae


brew search TEXT

As with many package managers, these eight commands are enough for most user interactions with Homebrew. However, Homebrew also has a lengthy man page that for some reason is not installed with it [6]. Some of the options are specific to developers creating formulae, such as the spellcheck typecheck command or the analytics command for repositories, and will not be discussed here for lack of space, but a number are also useful for convenience or administration purposes. For example, among the convenient options are completion, which autocompletes typed commands once enabled for a Bash, Zsh, or fish shell by linking to online dictionaries [7]. Similarly, home or homepage, qualified by a formula's or cask's name, opens to the target's web page so you can learn more about them. In addition, once you have mastered Homebrew's jargon, there are sub-commands and options for dealing with formulae in groups, instead of individually.

The administrative options include a number of options that help keep a system current. For instance, cleanup action uses the --prune DAYS option to remove files in Homebrew's cache that are older than a certain number of days or -s to remove the cache entirely. Another potentially useful action is outdated, which lists formulae for which a newer version is available. This is especially useful when accompanied by the action migrate, which takes options for when a formula's name is changed in a newer version, or bump, which sets whether an older version should be updated.

A Niche App

Homebrew is a comprehensive package manager. Despite the fact that it is only 13 years old, in many ways it is as far-reaching as the much older apt-get or Yum. It even includes features that could be useful in other package managers. However, access to Homebrew's advanced features is partially blocked by unnecessary jargon. As well, while its formulae must number in the thousands, they are nowhere near, for instance, Debian's 60,000 packages. It is only in the Ruby on Rails community that Homebrew is likely to dominate. For the rest of us, these notes should be enough to use Homebrew when a developer decides to use it, with a minimum of fuss and only a slight loss of convenience.

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest coast art ( He is also cofounder of Prentice Pieces, a blog about writing and fantasy at

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • McFly

    When it comes to working at the command line, using Bash history effectively can save you time. McFly extends the Bash history's features and helps you find past commands more quickly.

  • GitHub with hub

    The handy hub command-line tool lets you manage your GitHub repository from a terminal window, which can make it easier to automate repetitive tasks.

  • navi

    When the history function fails and the manpage is too long, navi comes to the rescue with an interactive cheat sheet for the shell.

  • Oh My Posh

    Adapt the terminal's available feature set and appearance with the Oh My Posh prompt theme engine.

  • Free Software and Beer: Not just for breakfast anymore!
comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More