Skip to content

Instantly share code, notes, and snippets.

@KevinVerre
Last active March 24, 2025 03:39
Show Gist options
  • Save KevinVerre/045d93f1ed8b66743e1bd48f2b50d19c to your computer and use it in GitHub Desktop.
Save KevinVerre/045d93f1ed8b66743e1bd48f2b50d19c to your computer and use it in GitHub Desktop.
Kevin's Guide to Homebrew

Kevin's Guide to Homebrew

Homebrew (brew) is a package manager. It's designed to help you manage which apps you have install. As well as help you upgrade those apps or manage which versions you have installed. It's a command line app for Mac and Linux. It can install CLI apps and GUI apps.

It's difficult to explain homebrew well! It does many things. And uses strange terminology. Here is how I would explain brew. (Afterall, of the best ways to learn is to teach!)

https://formulae.brew.sh/ The official homebrew website for documentation on how to use brew.

You can use homebrew to manage the location(s) of where the apps are installed. By default, all of the command line apps you install are in a certain directory. Brew puts the path to that directory in your command line PATH. This helps you run the newly installed apps from your terminal. The folder where the installed apps are written to is called the "Cellar". The default location is: /opt/homebrew/Cellar (Apple Silicon) or /usr/local/Cellar (Intel Macs)

Formula: a ruby script that brew runs to order to install -- or uninstall -- a specific application. The steps inside the ruby code include downloading the files needed for the app. Then compiles and installs them. The ruby script also contains code for uninstalling (or deleting) if you no longer want that app installed. This allows homebrew to install bunch of different apps without having to host the apps themselves! The formula needs to have logic about which url to download the app from.

Formulae: the plural form of formula. Homebrew likes to use this word instead of formulas. It comes from Latin. But it makes Homebrew more confusing for beginners.

Cask: a ruby script that installs -- or uninstalls -- a GUI apps. Can be used to install apps into ~/Applications .

Homebrew can (optionally) help you start, stop, and restart background apps (services). For example, maybe you have a database or server that you always want running whenever your machine restarts. This is a feature of brew that you use by running brew service commands. Not every formula supports being run as a service.

Where are these ruby formula files hosted? And how is brew able to run them? They are hosted inside git repos. Brew commands use git to download the ruby files. And to keep your local copy of the ruby files up to date.

A git repo that is used to distribute formula is called a "tap". The two main, official taps are homebrew/core and homebrew/cask. But homebrew on github has some other repos as well, such as a repo for fonts. There are thousands of formulas in homebrew's official repos. Homebrew's official repos are open source and public. Anyone with the Internet can read the formulas that are hosted in homebrew's official repos. Anyone can use brew to download and run the formulas to install CLI or GUI apps from homebrew's official repos. You don't need a username or password or anything to use the formulas in homebrew's official repos. Are they safe to use? Maybe! Be careful not to run any code that is unsafe.

Here is where things get interesting. Anyone with a git server can make their own tap! It does not need to be on github, any git server can be used. That way you can run and use formula that isn't in one of the official homebrew repos. Since it is built on top of git, you can even require authentication/authorization to access your git repo tap. This means you can use git to host a private tap git repo. Of course, you want to be careful about what code you allow brew to run on your machine.

The code for the brew command line app itself is also open source.

Running brew update updates your command line. It also updates your copy of the formulas based on which taps you have configured.

Brew is written on Ruby but makes use of Git. Often times when people use Git, they use it to see the history of how files changed. For example, when you clone, you typically get not only the latest copy of every file but also every change made to every file. However, in git there is a concept call shallow cloning (or clone depth). This can be used to tell git to only fetch the latest version of each file. Brew uses this to help keep disk space small. Depending on which taps you have configured, brew might have a lot of formulas downloaded to your machine. But each formula is just the latest version of that formula file. And it's usually a small ruby file. Brew typically download's all of the formulas in a tap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment