Installing packages on Linux and Mac with Homebrew

Here's an introduction to Homebrew, an easy but unusual package manager that works with both Linux and macOS.

Ever heard of Homebrew? It’s a package manager with a very unusual feature. It allows ordinary users to install packages without using sudo, and it’s available for both macOS and Linux. While the tool on each of these systems is referred to as Homebrew, the Linux version installs as linuxbrew.

Once installed, users can use Homebrew via the brew command to install packages very easily. Installation of Homebrew itself, however, does generally require sudo privileges and installs in /home/linuxbrew.

The man page for the brew command calls it “The Missing Package Manager for macOS (or Linux)”.

Advantages of Homebrew

Some advantages of Homebrew:

  • It’s pretty darn easy to use and provides an easy, flexible way to install Linux tools
  • It installs packages without requiring sudo
  •  you can use it on macOS and Linux

To get your system ready with updates and prerequisites, run these commands:

$ sudo dnf update
$ sudo dnf groupinstall ‘Development Tools’ && sudo dnf install curl file git
$ sudo dnf install libxcrypt-compat

It can take a while to complete these tasks, especially if your system hasn’t been updated recently.

Next, to install Homebrew in /home/linuxbrew/.linuxbrew, run this command:

$ /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

The command will prompt you at some point to enter your password.

To test it out, you can install some tools with commands like these:

$ brew install fortune
Updating Homebrew...
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
aws-sso-util
==> Updated Formulae
Updated 133 formulae.

==> Downloading https://ghcr.io/v2/linuxbrew/core/fortune/manifests/9708-4
########################################################################
==> Downloading https://ghcr.io/v2/linuxbrew/core/fortune/blobs/sha256:64feb5e5c695578
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:6
######################################################################## 100.0%
==> Pouring fortune—9708.x86_64_linux.bottle.4.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/fortune/9708: 82 files, 2.4MB

(Notice the cute little mug of brew at the bottom left.)

Trying out your installed app might look like this:

$ fortune
Space is to place as eternity is to time.
               —Joseph Joubert
$ which fortune
/home/linuxbrew/.linuxbrew/bin/fortune

In the command show below, a second package is installed:

$ brew install hello
==> Downloading https://ghcr.io/v2/linuxbrew/core/hello/manifests/2.10
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/hello/blobs/sha256:f81d7c0a3eee9fd62
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:f
######################################################################## 100.0%
==> Pouring hello—2.10.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/hello/2.10: 52 files, 595.7KB

Your linuxbrew directories will look something like what you see below.

$ ls -ld /home/linuxbrew
drwxr-xr-x. 3 root root 4096 Sep 30 14:51 /home/linuxbrew
$ ls -a /home/linuxbrew
.  ..  .linuxbrew
$ ls -l /home/linuxbrew/.linuxbrew
total 48
drwxrwxr-x.  2 shs shs 4096 Oct  6 16:17 bin
drwxrwxr-x.  2 shs shs 4096 Oct  4 15:30 Caskroom
drwxrwxr-x.  3 shs shs 4096 Oct  6 16:17 Cellar
drwxrwxr-x.  3 shs shs 4096 Oct  4 13:17 etc
drwxrwxr-x.  2 shs shs 4096 Oct  4 12:54 Frameworks
drwxr-xr-x. 11 shs shs 4096 Oct  4 15:45 Homebrew
drwxrwxr-x.  2 shs shs 4096 Oct  4 13:17 include
drwxrwxr-x.  2 shs shs 4096 Oct  4 13:17 lib
drwxrwxr-x.  2 shs shs 4096 Oct  6 16:17 opt
drwxrwxr-x.  2 shs shs 4096 Oct  4 13:17 sbin
drwxrwxr-x.  6 shs shs 4096 Oct  6 16:17 share
drwxrwxr-x.  3 shs shs 4096 Oct  4 15:30 var

To display the packages installed with the brew command, do this:

$ brew list
==> Formulae	        <== package browser
fortune  hello	        <== installed packages

In the output shown above, Formulae is the package browser. The second line lists the installed packages.

To remove a package installed by Homebrew, use either the brew uninstall or the brew remove command. They both do the same thing—uninstall the specified package.

$ brew remove hello
Uninstalling /home/linuxbrew/.linuxbrew/Cellar/hello/2.10... (52 files, 595.7KB)

Verifying the removal would look like this:

$ brew list
==> Formulae
Fortune	                  <== hello is gone

Homebrew does not make use of any libraries provided by your host system, except glibc and gcc if they are new enough. In addition, Homebrew can install its own current versions of glibc and gcc for older distributions of Linux.

Homebrew acts like a command-line package installer. It’s safe as long as you understand what you are downloading. It uses SHA256 as its package verification check.

Linuxbrew requirements

Current requirements for Linuxbrew include:

  • GCC 4.7.0 or newer
  • Linux 2.6.32 or newer
  • Glibc 2.13 or newer
  • 64-bit x86_64 CPU
Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.
Related:

Copyright © 2021 IDG Communications, Inc.

SD-WAN buyers guide: Key questions to ask vendors (and yourself)