Another cheat sheet for Homebrew (2022)

Essential concepts

What’s Homebrew?

Homebrew is a powerful package manager. It can ease your dev significantly, so do no hesitate to try it:

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/ins…

Essential concepts

What’s Homebrew?

Homebrew is a powerful package manager. It can ease your dev significantly, so do no hesitate to try it:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once it’s done, run brew and you should get the help menu to learn the various built-in commands of Homebrew. If so, you can now use a sets of command lines to manage packages on your machine.

Is Homebrew a Mac-only software?

Not at all, even if there are special configs and extensions for macOS.

Homebrew is available for Linux too. Windows users can use it but only with WSL (the Subsystem for Linux).

Homebrew uses symlinks

Behind the scene, Homebrew makes symlinks, which allows using third-party commands from packages in the terminal easily.

What are Homebrew Formulae?

A formula is a Ruby script that “provides instructions and metadata for Homebrew to install a piece of software”.

Technically, Homebrew formulae are subclasses of Formula. Homebrew uses them for package definitions.

What is “cask”?

You may have seen commands like brew install --cask tor-browser. Homebrew uses cask to deal with various licences and interact with graphical applications.

It’s particularly helpful to install apps from the terminal without having to drag and drop them into the /Applications/ directory.

Technically, cask is an extension of Homebrew but you don’t have to install it manually, it’s already packed with Homebrew.

What is “tap”?

Taps are useful to install formulae from alternative sources such as GitHub. When you use brew tap <FORMULA>, Homebrew considers it comes from GitHub by default but you can specify other locations:

brew tap [options] [user/repo] [URL]

What are bundles?

Bundles handle non-Ruby dependencies from Homebrew, Homebrew Cask, Mac App Store and Whalebrew. You can quickly list all bundles with:

brew bundle list

or:

less ~/Brewfile

Technically, bundle is an extension of Homebrew but you don’t have to install it manually, it’s already packed with Homebrew.

It’s a pretty elegant way to install softwares in macOS for engineers.

Why does homebrew force updates?

It’s not uncommon Homebrew updates some packages while you did not run brew update or brew upgrade. For example, when you install a new package, Homebrew analyzes libraries to add/remove required/outdated dependencies and keep things consistent.

Basic commands

Display all available commands

brew commands

Pretty cool to learn the tool!

Install a formula

brew install <FORMULA>

Uninstall a formula

brew uninstall <FORMULA>

Display information for a specific formula

brew info <FORMULA>

Display the homepage of a given formula

brew home <FORMULA>

The homepage URL is the one specified in the package’s metadata, for example:

class Git < Formula
  desc "Distributed revision control system"
  homepage "https://git-scm.com"

Search packages

brew search <KEYWORD>

Pretty self-explanatory but you can also use regex and interesting options such as --archlinux to restrict your search to a given database.

List all formulae including casks

brew list

You can use brew list --casks to list casks only.

List available updates

brew outdated

Update vs. upgrade

brew update updates everything, including Homebrew itself, whereas brew upgrade only updates installed formulae.

Note that you can also upgrade only a specific formula with brew upgrade <FORMULA>.

Cleaning stuff

You can clean old downloads with the following command:

brew cleanup 

Remove stale lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae.

It will remove all downloads more than 120 days old by default.

Most of the time, the command is safe to run, but you can use the --dry-run option if you’re not sure to visualize what will be removed instead of running it Yolo.

You can also clean for a specific formula only:

brew cleanup <FORMULA>

A bit more advanced usages

Pin / unpin

pin is used to prevent Homebrew from upgrading a package unless automatically when running a general update.

brew pin <FORMULA>

Use unpin to remove this exception:

brew unpin <FORMULA>

Link, unlink, or relink

brew link <FORMULA> allows you to customize symlinks. Use it only when necessary. To delete an existing symlink created with Homebrew, run brew link <FORMULA>.

You can also use brew unlink <FORMULA> && brew link <FORMULA> to relink a formula.

List all taps

brew tap

Remove taps

brew untap --force <TAP>

Locate the cache directory

brew --cache

Force cache delete manually

rm -rf "$(brew --cache)"

Troubleshooting: Config vs. doctor

brew doctor runs a quick diagnosis to spot errors whereas brew config displays Homebrew and system configuration info useful for debugging.

Expert mode 🥷🏻

Install Bundles

brew bundle install

Export the list of all brew entries

brew bundle dump

The above command generates a Brewfile you can reuse on other machines. By default, the file is located at the root of the $USER folder but you can specify a custom directory with the --file option.

mas

mas allows installing Mac apps from the App Store directly from the terminal:

brew install mas

All specific mas commands start with mas. All apps installed with mas are listed in the Brewfile.

Print a formula

brew cat <FORMULA>

Edit a formula

brew edit <FORMULA>

Enhance display for brew info <FORMULA>

brew info --json=v1 <FORMULA> | jq .

Create custom formulae

You can cook your own formulae:

class MyFormula < Formula
  desc "My Formula"
  homepage "https://mywebsite.com"
  url "https://example.com/foo-0.1.tar.gz"
  sha256 "85cc828a96735bdafcf29eb6291ca91bac846579bcef7308536e0c875d6c81d7"
  license "MIT"

  # depends_on "cmake" => :build

  def install
    # ENV.deparallelize
    system "./configure", "--disable-debug",
                          "--disable-dependency-tracking",
                          "--disable-silent-rules",
                          "--prefix=#{prefix}"
    # system "cmake", ".", *std_cmake_args
    system "make", "install"
  end

  test do
    system "false"
  end
end

Print Share Comment Cite Upload Translate
APA
Julien Maury | Sciencx (2024-03-28T14:52:06+00:00) » Another cheat sheet for Homebrew (2022). Retrieved from https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/.
MLA
" » Another cheat sheet for Homebrew (2022)." Julien Maury | Sciencx - Thursday March 24, 2022, https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/
HARVARD
Julien Maury | Sciencx Thursday March 24, 2022 » Another cheat sheet for Homebrew (2022)., viewed 2024-03-28T14:52:06+00:00,<https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/>
VANCOUVER
Julien Maury | Sciencx - » Another cheat sheet for Homebrew (2022). [Internet]. [Accessed 2024-03-28T14:52:06+00:00]. Available from: https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/
CHICAGO
" » Another cheat sheet for Homebrew (2022)." Julien Maury | Sciencx - Accessed 2024-03-28T14:52:06+00:00. https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/
IEEE
" » Another cheat sheet for Homebrew (2022)." Julien Maury | Sciencx [Online]. Available: https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/. [Accessed: 2024-03-28T14:52:06+00:00]
rf:citation
» Another cheat sheet for Homebrew (2022) | Julien Maury | Sciencx | https://www.scien.cx/2022/03/24/another-cheat-sheet-for-homebrew-2022/ | 2024-03-28T14:52:06+00:00
https://github.com/addpipe/simple-recorderjs-demo