Homebrew is a popular package manager for macOS that simplifies the installation, updating, and management of software packages. Whether you’re a developer, system administrator, or just a tech enthusiast, Homebrew can help you manage your software efficiently. This guide will walk you through some of the most useful Homebrew commands and tips.
Installing Homebrew
Before you can use Homebrew, you need to install it. Open your terminal and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions to complete the installation.
Basic Commands
Listing Installed Packages
To list all the packages installed via Homebrew, use the following command:
brew list
This will show a list of all installed formulae (command-line tools) and casks (GUI applications).
If you want to list only the casks, use:
brew list --cask
Listing Top-Level Packages
Homebrew installs dependencies automatically when you install a package. To list only the top-level packages (those you installed manually, not dependencies), use:
brew leaves
To include descriptions of these packages, you can use:
brew leaves | xargs brew desc --eval-all
Listing Installed Packages with Versions
If you want to see the versions of the installed packages, use:
brew list --versions
For casks, you can use:
brew list --cask --versions
Viewing Dependency Trees
To see the dependency tree of all installed packages, use:
brew deps --tree --installed
This will show you which packages depend on others, helping you understand the relationships between your installed software.
Managing Packages
Installing Packages
To install a package, use the brew install
command followed by the package name:
brew install <package-name>
For example, to install wget
, you would run:
brew install wget
Updating Packages
To update all installed packages to their latest versions, use:
brew update
brew upgrade
If you only want to see which packages are outdated, use:
brew outdated
For casks, use:
brew outdated --cask
Uninstalling Packages
To uninstall a package, use the brew uninstall
command:
brew uninstall <package-name>
For example, to uninstall wget
, you would run:
brew uninstall wget
Advanced Usage
Using Brewfile for Reproducible Setups
Homebrew allows you to create a Brewfile
that lists all your installed packages. This is useful for replicating your setup on another machine.
To create a Brewfile
from your currently installed packages, use:
brew bundle dump
This will generate a Brewfile
in the current directory. You can then edit this file if needed.
To install all the packages listed in a Brewfile
, use:
brew bundle
Migrating Packages to Another Machine
If you want to migrate your Homebrew setup to another machine, you can use the Brewfile
approach. First, create a Brewfile
on your current machine:
brew bundle dump
Then, transfer the Brewfile
to the new machine and run:
brew bundle
This will install all the packages listed in the Brewfile
on the new machine.
Cleaning Up Unused Packages
Homebrew can help you clean up unused packages and free up disk space. To remove unused packages, use:
brew autoremove
To clean up old versions of installed packages, use:
brew cleanup
Homebrew is a powerful tool that simplifies package management on macOS. Whether you’re installing new software, updating existing packages, or managing dependencies, Homebrew provides a straightforward and efficient way to handle it all. By mastering the commands and techniques outlined in this guide, you’ll be well-equipped to manage your macOS software with ease.
For more information, you can always refer to the official Homebrew documentation by running:
brew help
Happy brewing! 🍺