Thomas ʕ•ᴥ•ʔ Bear Blog

Unpacking Homebrew

What is Homebrew?

A package manager for macOS. If you're familiar with linux, it's similar to using apt or yum to install packages. Essentially, it's an easy way to install tools and code libraries through the command line.

Understanding the beer analogy

Ok, I've worked with a package manager before, but what are all these weird terms like "formula", "keg", "rack", "tap"? It'll make much more sense to you if you understand beer culture. Here's a brief and oversimplified introduction:

Beer overview

Tying it back to package managers

Homebrew overview

Getting started with Homebrew

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL"
==> This script will install:
==> The following new directories will be created:
==> The Xcode Command Line Tools will be installed.

# Install a package
$ brew install jq

# Show jq executable sym-linked into Cellar
$ ls -l /usr/local/bin
lrwxr-xr-x  1 thomasnguyen  admin         jq -> ../Cellar/jq/1.6/bin/jq

A few interesting things to notice:

Creating our own formula

As we've now learned, brew install is simply Homebrew executing a formula (ruby script) which defines how to install the package.

Let's try writing our own formula!

  1. Identify the .tar.gz executable you want to be able to install using brew. I've decided to create a formula for wget (

  2. Use brew create to generate a ruby script

    brew create --set-name my-wget
  3. Modify the Ruby script to include instructions on how to install

    class MyWget < Formula
      homepage ""
      url ""
      sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd"
      depends_on "gnutls"
      def install
        system "./configure", "--prefix=#{prefix}"
        system "make", "install"
  4. Run brew install on the formula we just created. Notice all the dependencies that need to be installed for my-wget and gnutls

    brew install --build-from-source my-wget
  5. Test and check. Notice that even though our formula is called my-wget, the executable we installed from gnu is still called wget.

    $ ls /usr/local/Cellar/my-wget/1.15/bin
    $ ls -l /usr/local/bin/wget
    lrwxr-xr-x  1 thomasnguyen  admin  /usr/local/bin/wget -> ../Cellar/my-wget/1.15/bin/wget
    $ wget

Other tidbits


#linux #tech