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
-
Gnome OS Adopting systemd-sysupdate
Gnome OS is about to undergo a major under-the-hood change that promises enhanced security.
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.