Michiel Kempen

Michiel Kempen

Hi, I'm Michiel, a passionate cloud engineer, full-stack webdeveloper,
and entrepreneur. I love to learn, teach, and build awesome things.
Currently making the cloud accessible at Smoothy.cloud ☁️🚀

Getting started with Homebrew on Mac #

If you are a seasoned Mac-user you may have already heard about Homebrew. In fact, chances are you may have used it to configure this very Mac. If this is the case, great! Welcome to the cool club. 😎 However, if Homebrew is completely new to you or you have never used it before, you are in for a treat! 🍭

Simply said: Homebrew is a package manager for Mac. It is to Mac what

  • Composer is to PHP
  • NPM is to JavaScript
  • Pip is to Python
  • Maven is to Java

Homebrew makes it very easy to install, update, and delete additional software on your Mac and brings structure in the otherwise chaotic world of version conflicts, broken installations, and security vulnerabilities.

Say, for example, you want to install Git and PHP on your machine. Instead of browsing the web and downloading and installing the associated binaries manually, you simply type brew install git php and Homebrew handles the rest for you. Cool, right?

Formulae and taps #

Packages that can be installed through Homebrew are called formulae. A formula is a Ruby-based file that defines how a certain package can be installed. By default, Homebrew looks for available formulae in homebrew-core, an extensive open-source catalog maintained by thousands of contributors.

In Homebrew terms, such a catalog is referred to as a tap. Apart from the default tap, there are numerous other taps available online. For example, if you want to install MongoDB through Homebrew, you can add the MongoDB tap to your Homebrew installation by running:

brew tap mongodb/brew

Once the tap has been added, the MongoDB formula can be installed using:

brew install mongodb-community

You can also create your own tap, in case you want to distribute your own packages through Homebrew. To do so, you simply create a public GitHub repository named <username>/homebrew-<something> and put the formulae of your packages in it. Next you run brew tap <username>/<something> in a terminal on a Mac and subsequently your formulae are available for installation through brew install <formula>.

Brew under the hood #

Based on the contents of a formula, Homebrew knows how to install the corresponding package on your Mac. However, instead of scattering files across your filesystem, Homebrew groups all the installed packages in a single location called the Cellar, which is located under /usr/local/Cellar.

For example, if you run brew install git, Homebrew installs Git under /usr/local/Cellar/git/<version>/, with the git binary in /usr/local/Cellar/git/<version>/bin/git. However, since executable binaries should be placed in the /usr/local/bin folder on MacOS, Homebrew creates a symlink from /usr/local/Cellar/git/<version>/bin/git to /usr/local/bin/git.

This way, your filesystem remains clean and provides you a bird's-eye view of all the packages installed on your machine.

Homebrew cask #

And just when you started to think installing software on your Mac could not get any better, it can. 🤯

Meet Homebrew cask.

Homebrew cask is an extenstion of Homebrew which enables you to install graphical applications such as Google Chrome or Atom through brew. All the underlying principles are basically the same. The only difference is that formulae in cask are referred to as casks, and the default tap is now located under homebrew-cask.

You can enable Homebrew Cask by adding the cask tap to your local Homebrew installation:

brew tap caskroom/cask

After that, installing an application such as Atom is as easy as running:

brew cask install atom

Installing Homebrew #

I hope that by now you have seen the value that Homebrew can bring into your life and that you cannot wait to try it out yourself. If that is the case, good news! You are only one command away of having a Homebrew installation on your Mac:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After the installation has completed you can verify its correctness by requesting the version of your Homebrew installation by running:

brew --version

This should return something like:

Homebrew 2.2.3
Homebrew/homebrew-core (git revision 76ca9; last commit 2020-01-18)

Updating Homebrew #

Homebrew as well as its formulae are continuously being improved. Therefore it is important to update your Homebrew installation before installing or upgrading any software package on your machine.

brew update

Uninstalling Homebrew #

If you are tired of Homebrew and rather fall back on the medieval practise of manually downloading and installing packages, you can uninstall Homebrew using the following command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Generate HTTPS URLs when running Laravel behind a proxy