A Guide To Homebrew
When using Terminal on Mac, if you want to install a command line package you could certainly install the package globally and update it manually. However, if you have many packages it might be laborious to manage them all. Homebrew lets you manage and update them all at once. I will cover the most useful things first.
Quickstart
Install Homebrew by running a command from the Homebrew website. This uses curl to download a Bash script from the Homebrew GitHub project and run it.
To install a package
brew install <formula>
To update the database of packages
brew update
To actually update all packages, run this. Homebrew also updates itself when this run.
brew upgrade
To list all main packages installed
brew leaves
To uninstall a package
brew uninstall <formula>
Some Links
Homebrew homepage https://brew.sh
Homebrew manual page https://docs.brew.sh/Manpage
The formulae database https://formulae.brew.sh/formula/
GitHub https://github.com/Homebrew/brew
Glossary https://docs.brew.sh/Formula-Cookbook#homebrew-terminology
Glossary
Homebrew’s features are themed on alcohol and brewing.
I will use “package” and “formula” interchangeably.
Summary: formula > keg > rack > Cellar
The rest are technical and not really worth learning unless something goes wrong e.g. keg, cellar, bottle, tap
Term | Descripion |
---|---|
formula | A Ruby script file defining a package and its install source URL. Or a “package definition”. |
keg | A directory containing one version of a formula. |
rack | A directory containing all kegs (all versions) of a formula. |
Cellar | A directory containing all racks. There is only one cellar per system. |
tap | The install link (“upstream source”) of a formula if it is defined and tracked separately from the one in the formula description. Usually a Github repository. |
poured | The term for installing from a tap. |
bottle | “A pre-built keg poured into a rack of the Cellar instead of building from upstream sources.” |
cask | A package definition for a macOS native application. |
The Database | My term for Homebrew’s curated list of packages and their formula descriptions. |
Extra Information
Homebrew maintains a curated list of popular packages. There is a web interface for viewing the database. I assume a package developer asks the Homebrew maintainer to add their package to the list.
Homebrew automatically installs the dependent files in the system folders and removes them when uninstalled.
Dependencies are shared between packages, instead of installing twice. When a package is upgraded and a dependency is found to be installed already, it is skipped.
List all packages installed including dependencies
brew list
List all packages with versions including dependencies
brew list --version
Show package information such as if and where it is installed, version, required and optional dependencies, download source, and any older versions installed. But the formula website is more convenient
brew info <formula>
To list all installed packages and their dependencies in a tree format
brew deps --tree --installed
To count the packages (“kegs”) including dependencies
brew info
To detect and uninstall all formulae that were installed as a dependency of another formula and are now no longer needed. Perhaps because the formula no longer uses it, or the formula was uninstalled.
brew autoremove
To list what would be uninstalled without doing anything
brew autoremove -n
To remove old versions of formulae, outdated downloads, stale lock files. Can target one formula. Removes all downloads more than 120 days old, this can be configured.
brew cleanup
Homebrew automatically updates itself when certain sub-commands are run: ‘instal’, ‘update’, ‘upgrade’
Maintenance
Homebrew changed how it works from version 4.0.0 onwards. Now formulae are downloaded via a JSON file from https://formulae.brew.sh instead of the GitHub repository “https://github.com/homebrew/homebrew-core"
brew update
returned:
Installing from the API is now the default behaviour!
You can save space and time by running:
brew untap homebrew/core
brew untap homebrew/cask
So I did. The errors ceased
brew untap homebrew/core homebrew/cask
To list current taps
$ brew tap