I’ve been using macOS heavily for over a year now. I came from a Linux background, starting with Ubuntu and apt, then switching to pacman. Using macOS at my day job eventually got me to buy a Mac of my own, and it’s been my daily driver since. Like most people on macOS, I use Homebrew as my package manager, and this post covers some of its lesser-known commands and features.
What Homebrew is
Homebrew, often referred to as brew, is a popular package manager for macOS and Linux operating systems. It provides a convenient way to install, update, and manage software packages and libraries on your system. Homebrew simplifies the process of installing and maintaining software by automating the downloading, compiling (if necessary), and installation of packages.
Homebrew is written in Ruby and uses Git for version control. It was created by Max Howell in 2009 and is currently maintained by a team of developers. Homebrew is open-source and distributed under the BSD 2-Clause License.
Here are some key features and aspects of Homebrew:
- Package Management: Homebrew allows you to easily install a wide range of software packages, including command-line utilities, libraries, and applications, from a central repository.
- Dependency Management: It automatically handles dependencies for you, ensuring that all required components are installed when you install a package.
- Casks: In addition to command-line software, Homebrew Cask extends Homebrew’s functionality to include GUI applications. This is especially useful for installing and updating graphical software.
- Taps: Homebrew supports the concept of “taps,” which are additional repositories maintained by the community or individuals. Taps allow you to access packages not found in the core Homebrew repository.
- Custom Formulas: Users can create custom formulas (recipes) to install software that isn’t in the main repository. This feature is handy for maintaining your own packages or adding packages from other sources.
Lesser-known Homebrew commands
This section covers some of the lesser-known commands and advanced features of Homebrew. You can find more on all of these by running brew help or man brew.
Create a formula for a package
The brew create command builds a new formula for a software package from a URL to its source code.
brew create < URL_to_source> ; Running this command does the following:
- Downloads the source code from the specified URL.
- Generates a new formula file in Homebrew’s formulae directory, typically named after the package, with a
.rbextension.
This is useful for adding packages that aren’t part of the official repository, letting you create and manage your own custom formulas.
Retrieve package information
brew info < package_name> ; This retrieves information about a package: its version, dependencies, installation path, homepage URL, and the formula file used to install it.
List installed packages
brew list This lists all installed packages on your system. You can also list casks by running brew list --cask.
Start a Homebrew interactive shell session
brew sh This starts an interactive shell session with Homebrew. It’s useful for testing commands and experimenting with Homebrew’s functionality, since the shell is isolated and doesn’t touch your system’s global environment. Good for trying out packages or testing configurations without risk.
Dump installed packages to a Brewfile
brew bundle dump This dumps all installed packages into a Brewfile, useful for sharing your package list with someone else or reinstalling the same set on another system.
Upload install logs with brew gist-logs
brew gist-logs <package_name> uploads the install logs for a specific formula to a GitHub Gist. It’s helpful for debugging Homebrew issues or asking the Homebrew community for help.
Last but not least, here’s a script I wrote that uses brew to list all installed packages with their sizes in a human-readable format.
brewpackages ( ) { brew list --formula | xargs -n1 -P8 -I {} \ sh -c "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | \ sort -h -r -k2 - | column -t } Whether you’re a seasoned Homebrew user or new to package management, these commands can make day-to-day work easier. I hope this was useful. If you have questions or comments, leave them below.
If you liked this post, you can support my work by buying me a coffee. It would mean a lot. You can also follow me on Twitter, and tag me @muhammad_o7 if you share this post there.