Using Homebrew with a minimum of fuss
Command Line – Homebrew
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 https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
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
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].
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].
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
Action | Command |
---|---|
Install |
|
Remove |
|
Auto-remove dependencies |
|
Upgrade formula |
|
Upgrade all formulae |
|
List installed formulae |
|
List available formulae |
|
Search |
|
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.
Infos
- Homebrew: https://brew.sh/
- Install Homebrew: https://docs.brew.sh/Installation
- How to Install and Use Homebrew on Linux: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-homebrew-on-linux
- Common issues: https://docs.brew.sh/Common-Issues
- Jargon and formulae: https://docs.brew.sh/Formula-Cookbook#homebrew-terminology
- Man page: https://docs.brew.sh/Manpage
- Shell completion: https://docs.brew.sh/Shell-Completion
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.