Resources

Install Homebrew

See the brew.sh homepage.

This will request your password as it needs root permissions.

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

See install.sh on GitHub.

If upgrading Homebrew, it is recommended to then upgrade all packages.

Update list

Update Homebrew’s local list of packages.

This does not actually update packages. Note you probably don’t need to use this, since an update is done before commands like install.

$ brew update

Install packages

If a package is already installed and you install it again, you’ll get an error message telling you to upgrade it instead.

Install selected package

Install a specific package by its formula.

Note: Unlike apt, the update command is done internally to get the latest remote info - #1670.

$ brew install PACKAGE
$ brew install PACKAGE@VERSION

e.g.

$ brew install gcc@7 python@3.9

Warning: The default behavior is for the install command to automatically upgrade all installed packages. This has caused issues for me where Python environments broke when upgrading something unrelated to Python.

Install without auto-upgrade - from article.

$ HOMEBREW_NO_AUTO_UPDATE=1 brew install PACKAGE

Or set once-off in .bashrc or .zshrc so it is always set.

export HOMEBREW_NO_AUTO_UPDATE=1

Install a cask

See also Homebrew casks.

$ brew cask install CASK_NAME

Upgrade packages

Outdated

List outdated packages - including current and latest versions.

$ brew outdated

Upgrade selected package

$ brew upgrade PACKAGE

Warning: This will also upgrade dependents.

e.g. Upgrading shfmt upgraded these too:

...
==> Upgrading shfmt 2.6.4 -> 3.3.0
...
==> Upgrading 14 dependents:
cython 0.29.21 -> 0.29.23, gnutls 3.6.15 -> 3.6.16, httpie 2.2.0_1 -> 2.4.0, ipython 7.18.1 -> 7.24.0, krb5 1.18.2 -> 1.19.1, libxml2 2.9.10_1 -> 2.9.12, libxmlsec1 1.2.30 -> 1.2.32, mysql-client 8.0.21 -> 8.0.25, mysql-connector-c++ 8.0.21 -> 8.0.25, pyenv 1.2.21 -> 2.0.0, python@3.8 3.8.6 -> 3.8.10, python@3.9 3.9.0 -> 3.9.5, sphinx-doc 3.2.1_1 -> 4.0.
...

Upgrade all packages

Update outdated packages. WARNING Use this with caution - it can break Python virtual environments for example.

$ brew upgrade --dry-run

$ brew upgrade

Here is a shortcut I found - from article.

alias brewery='brew update && brew upgrade && brew cleanup'

Help

$ brew upgrade --help
Upgrade outdated, unpinned formulae using the same options they were originally
installed with, plus any appended brew formula options. If formula are
specified, upgrade only the given formula kegs (unless they are pinned; see
pin, unpin).

Unless HOMEBREW_NO_INSTALL_CLEANUP is set, brew cleanup will then be run for
the upgraded formulae or, every 30 days, for all formulae.

Remove

$ brew uninstall PACKAGE

Taps

$ brew tap <TAP_NAME>/taps
$ brew install <TAP_NAME>

e.g.

$ brew tap isacikgoz/taps
$ brew install gitbatch

You can run brew link directly but it also runs as part of install or upgrade.

If a symlink cannot be created, you will get an error message with instructions, added here as well for convenience.

To force the link and overwrite all conflicting files:

brew link --overwrite PACKAGE

To list all files that would be deleted:

$ brew link --overwrite --dry-run PACKAGE

Sample of a full message:

==> Pouring six--1.16.0_2.all.bottle.1.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/python3.9/site-packages/six.py
Target /usr/local/lib/python3.9/site-packages/six.py
already exists. You may want to remove it:
  rm '/usr/local/lib/python3.9/site-packages/six.py'

To force the link and overwrite all conflicting files:
  brew link --overwrite six

To list all files that would be deleted:
  brew link --overwrite --dry-run six

Possible conflicting files are:
/usr/local/lib/python3.9/site-packages/six.py

Services

Set up a service to start now and then start up whenever you boot the machine. This uses launchd.

Example

Sample instructions given when installing dnsmasq.

To have launchd start dnsmasq now and restart at startup:

$ sudo brew services start dnsmasq