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
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.