What is Homebrew?

Homebrew is a package manager for MacOS and Linux systems. Although it is called homebrew, the command is shortened to brew.

The thing about homebrew is that every command and option sticks to the theme of brewing. I haven’t gone and dug out why this is the case, but I found it amusing.

As I had used homebrew a couple of times when setting up my work laptop and now setting up my own, I got curious and wanted to know what options the command accepted. The brewery terminology also was intriguing.

Learn more about homebrew here - https://docs.brew.sh/Manpage

So to view all there is that you need to know about homebrew, you could either open that link, or you can just type in man brew in your command line and that should open up the manpage for you in your terminal!

Let’s get some terminology out of the way.

Formula

According to the manpage, it is a package definition built from upstream sources.

This definition was not good enough for me.

I was like what does upstream sources mean here? Where is this source? So I did a search online like I do a 1000 times a day, and I came across this https://docs.brew.sh/Formula-Cookbook

So a formula for Homebrew is actually a package definition written in Ruby! That is a lot clearer!

Homebrew doesn’t know all the formulae in the world, the default known to homebrew can be seen at Homebrew/homebrew-core.

A formula script contains instructions to the location of the tar or archive of the application you are trying to install. The script also knows how to build the application.

You can create one of your own formulae using the command brew create path-to-zip-or-tarball.

That’s how you package your application for brew. You can then use brew’s installer debugger by running another command brew install –debug –verbose name-of-your-formula.

Bottles

While we are at it, not every package has to be compiled like this from source code. Homebrew allows installation of binary applications that do not need to be built from scratch. These are Bottles.

Cellar

Homebrew installs all applications in a Cellar. This is the root directory where homebrew stores all the software installed and built using homebrew.

Homebrew installs things into the Cellar and then creates symlinks to /usr/local to make all the good stuff that’s installed accessible to other applications.

Keg

The doc says that Keg is the installation prefix of a Formula! And gives an example path! That wasn’t clear at all to me!

In reality it is the path where a formula is installed in your computer. In your Cellar, homebrew will install a package by creating a directory for each formula-name/version. That fully qualified path is a Keg.

So in summary, you put a formula in a Keg, in the Cellar. Get it?

keg-only

There are times when installing something homebrew detects that creating a symlink in /usr/local could actually create conflicts with already installed applications. In these scenarios, homebrew could do something called a keg-only installation.

By that it means, you can access your application, only via the keg - i.e by providing a fully qualified path to the application. It won’t be available globally for execution.

Rack

Rack is where all the kegs of a formula are. E.g. if a keg is /usr/local/Cellar/foo/0.1, then the the rack is /usr/local/Cellar/foo.

If it is any easier to remember, it is the root folder of the application in the Cellar.

Tap

A tap is what gives you formulae. It is a public git repository comprised of a set of formulae.

You can use brew tap url/to/git-repo/that/is/a/tap to make a formula source available to brew. As mentioned earlier, when installed, brew would only be aware of the core formulae, anything beyond that must be communicated to brew.

Cask

This is a MacOS only extension of brew that allows you install native MacOs apps from the command line! So when the virgin brew allows you to install tarballs and archives from ruby scripts, cask lets you install full blown .dmg files.

Bundles

As the name suggests, a bundle is a group of related applications that you can install at once! Instead of manually doing installation of formulae one by one.

A bundle is really just a file named Brewfile that lists out several different taps and formulae.

You would generally install a bundle using: brew bundle install name-of-bundle

brew bundle name-of-bundle would also do the install.

You can choose to install from a Brewfile you have downloaded too: brew bundle --file=path/to/brewfile

Updates

Occasionally you have to run some updates too. That’s when you run brew update formula. If you ran the command without mentioning the name of a specific formula, brew would update all the formulae that it knows of in the system and also update itself! Handy!

Upgrade

Upgrade on the other hand - does major version upgrades, unlike its sibling update. It also behaves the same way as the update command. If you specify a formula name, that specific formula is upgraded, else everything that is outdated is upgraded.

Uninstall

I don’t think I have to explain here. brew rm formula or brew uninstall formula.

Cleanup

brew cleanup formula

Removes outdated version of a formula, does this for all formulae if none is specified. Good idea to do this after an upgrade.

That’s all for now

Happy brewing!