Homebrew — the MacOS and Linux Package Manager That Will Make You Smile
It’s free and it’s easy.
MacOS has an app store, but does that contain all the software you need? No. Especially when you’re an advanced user, like a developer or a scientist, you’ll find that MacOS lacks a good package manager. You want something like yum, or apt-get. Something with which you can install anything with a single command. No downloading and extracting. No manual compiling. That’s where Homebrew comes in!
What is Homebrew?
Homebrew is the missing package manager for macOS. That’s their slogan… and it’s so true. Homebrew allows you to install the stuff that Apple doesn’t offer you. Have you ever needed the latest version of Python, xz, wget, tmux, FFmpeg, untar, <insert any piece of software here> on your Mac?
And these are just the command line tools and libraries, also called “formulae”. But there are also “Casks”. With a cask, you can easily install GUI software from the command line. No more “drag to install”. Here’s the list of casks that are available today.
Installation couldn’t be simpler. Paste the following command in a terminal prompt and the installer will be downloaded and executed. The script explains what it will do and then pauses before it does it.
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(if this is broken up in multiple lines: it should all be on one line after you paste it in your terminal)
Well, that was easy. Now let’s install something.
You may want to have
unrar on your system, it’s a nice and small decompression tool that’s missing on the Mac:
$ brew install unrar
Bam! You’re done.
Want to try Chromium, the stripped, open-source version of Google Chrome? Here you go:
$ brew cask install chromium
You now have an extra browser at your disposal.
Want to update all your packages to the latest versions?
$ brew upgrade
Or a specific package:
$ brew update unrar
Uninstalling a package is done with:
$ brew uninstall <package>
You can search for casks and formulae using
brew search. For example:
$ brew search firefox
See that? You can install 6 versions of Firefox. How awesome is that?
Where do packages get installed?
If you like to know a little more about how brew works, read on. There’s no magic going on and it’s easy to modify formulae on your system. You can inspect and edit a formula yourself simply by using
brew edit <formula>. Let’s look a the formula of the xz compression tool with
brew edit xz:
As you can see, there is a description, link to the homepage, the download URL of the tarball, an extra mirror URL and a sha256 hash used to verify the integrity of the download. There are no dependencies, but if there were they would be listed as well.
Next, there is the install function. It contains a couple of system calls. If you’ve ever compiled source code yourself, the
make install riddle will look familiar. It’s simply doing all the stuff you would otherwise do by hand.
After compilation, brew will place the software in what is called the Cellar. Every package ends up in a directory structure that looks like:
To make this more concrete, the xz binary on my system is installed in:
If you enter
which xz you’ll discover that xz is found in
/usr/local/bin/xz . What happens is that brew creates a symlink to the latest version in
/usr/local/bin. You can link and unlink formulae yourself with
brew link and
brew unlink, if you want to disable a piece of software for whatever reason without completely uninstalling it.
Works on Linux too
Homebrew can be installed on Linux too. But why would you need it, if your distro already comes with a great package manager? Well, one reason can be that Homebrew will install the packages without needing superuser permissions. Another reason can be that Homebrew might have packages that your distro does not have. And the most important reason is that Homebrew packages are almost always up-to-date, meaning that you’ll usually get the latest releases of the stuff you install.
If you got this far, I think you will be interested in the following article I wrote as well:
If you liked this article and want to be notified when I post new stuff, please subscribe to my mailing list.