Introduction
Homebrew is a package manager for macOS and Linux that allows applications to be installed via the command line. It provides a practical way to set up, update, or remove software on macOS, which does not have a native CLI package manager.
In this tutorial, learn how to install and use Homebrew on macOS with examples.
Prerequisites
- A system running macOS Big Sur or newer.
- Administrative privileges.
How to Install Homebrew on Mac
Setting up Homebrew on macOS involves installing Xcode Command Line Tools and running the Homebrew installation script. The following sections explain the installation and post-installation procedure and show how to manage Homebrew formulae (i.e., software packages).
Follow the steps below to install Homebrew on Mac.
Install Xcode Command Line Tools
Xcode is an integrated development environment for macOS containing command-line tools Homebrew needs to function properly.
Note: Xcode is a prerequisite for many other tools on macOS, such as PuTTY, a telnet and SSH client.
Proceed with the steps below to install Xcode Command line tools:
1. Run the following command in Terminal:
xcode-select --install
Note: View a comprehensive list of Mac terminal commands for quick refrence when working in macOS terminal. The article also includes a downloadable PDF cheat sheet.
2. Click Install when prompted to proceed with the installation.
The script displays the Xcode License Agreement.
3. Click Agree and wait for the installation to finish.
Install Homebrew
With Xcode Command Line Tools on the system, enter the following command to run the Homebrew installation script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter the administrator password when prompted and press Enter to continue.
The message appears to confirm the installation was successful.
Note: If you do not like Homebrew, try Pip, another package manager available on Mac. See how to install Pip on Mac.
Turn Off Analytics
By default, Homebrew collects the following system information:
- The Homebrew user agent.
- Google Analytics version.
- Homebrew analytics tracking ID and Homebrew analytics user ID.
- Events (for example, the Homebrew
install
event category).
Enter the following command to disable the analytic data collection:
brew analytics off
The command produces no output. Check the analytics status by typing:
brew analytics
The output shows the analytics have been disabled.
Install, Update, or Remove Packages
Homebrew features a simple syntax that facilitates package management on macOS.
Use the following command to install a formula using Homebrew:
brew install [package name]
For example, enter the following to install the tree
command:
brew install tree
The command updates the Homebrew formula list and installs the tree
command.
To update a specific formula, type:
brew update [package name]
Enter the following command to check if any formulae need updating:
brew upgrade
On a fresh Homebrew installation, the output shows everything is up to date.
Remove a formula from the system with the following syntax:
brew uninstall [package name]
For example, enter the command below to uninstall the tree
formula:
brew uninstall tree
Installing Desktop Applications
Homebrew casks allow the package manager to install GUI applications. For example, install the Firefox browser by adding the --cask
flag:
brew install --cask firefox
Visit the Homebrew website for the full list of available casks.
How to Uninstall Homebrew on Mac
Remove Homebrew from the system by running the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
When prompted, type y
and press Enter to uninstall Homebrew.
Common Homebrew Commands
The following table lists some of the most used commands when working with Homebrew.
Command | Description |
---|---|
brew install [formula] | Installs a new formula. |
brew update | Updates Homebrew itself to the latest version. |
brew upgrade | Upgrades all outdated formulae. |
brew search [query] | Searches for formulae matching the given query. |
brew info [formula] | Displays detailed information about a specific formula. |
brew uninstall [formula] | Uninstalls a specific formula. |
brew install --cask [cask] | Installs a Cask (for GUI applications). |
brew doctor | Checks for and tries to fix common problems with the Homebrew installation. |
brew cleanup | Removes old or unnecessary files related to Homebrew. |
Conclusion
After following the steps in this tutorial, you should have a working Homebrew installation on your system. The article also provided a brief introduction to managing packages using Homebrew.
For the Linux tutorial, read How to Install Homebrew in Linux.