Homebrew is a popular, free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system and Linux. Often referred to as the “missing package manager for macOS,” Homebrew allows users to easily install command-line tools, applications, and libraries that are not readily available through the standard operating system interfaces or app stores. This guide will walk you through the process of installing Homebrew, setting up your environment, and leveraging its capabilities to enhance your development workflow.
Understanding Homebrew: The Power of Package Management
Homebrew operates by downloading source code or pre-compiled binaries (called “bottles”) from the internet and compiling them on your local machine, or by simply placing them in the correct locations to be executable. This process is managed through a series of scripts and a robust “formula” system. Formulas are Ruby scripts that define how to build and install a specific piece of software. When you request to install a package, Homebrew fetches its corresponding formula, resolves any dependencies, and then executes the build and installation steps.

Why Use Homebrew?
The primary advantage of using Homebrew is the ease with which you can install and manage software. Without a package manager, installing many command-line utilities or developer tools would require manual downloading, compiling from source, and careful management of dependencies. This can be a time-consuming and error-prone process.
Homebrew simplifies this by:
- Automating Installations: With a single command, you can install complex software packages.
- Managing Dependencies: Homebrew automatically identifies and installs any required libraries or tools that a package depends on.
- Keeping Software Updated: It provides straightforward commands to update all installed packages to their latest versions.
- Uninstalling Cleanly: Removing software installed via Homebrew is as simple as installing it.
- Providing Access to a Vast Repository: Homebrew’s “Formulae” repository contains thousands of popular and niche software packages, covering everything from programming languages and databases to developer tools and utilities.
Homebrew on macOS vs. Linux
While Homebrew originated for macOS, it has been successfully ported to Linux and is often referred to as Linuxbrew. The installation process is remarkably similar across both platforms, with minor variations in initial setup. This guide will primarily focus on macOS installation, but the principles and commands are largely transferable to Linux environments.
Installing Homebrew on macOS
Before you begin the installation, ensure you have the necessary prerequisites. For macOS, this includes:
- macOS: A recent version of macOS is recommended.
- Xcode Command Line Tools: These provide essential development tools like compilers, Git, and other utilities needed for building software.
Step 1: Install Xcode Command Line Tools
If you don’t already have Xcode or its command-line tools installed, you can install them from the terminal. Open your Terminal.app and run the following command:
xcode-select --install
This command will launch a graphical installer. Follow the prompts to complete the installation. If you already have Xcode installed, you might be prompted to update the command-line tools if they are outdated.
Step 2: Run the Homebrew Installation Script
Once the Xcode Command Line Tools are installed, you can proceed with installing Homebrew itself. Homebrew’s installation script is designed to be run directly from your terminal.
Navigate to the official Homebrew website (brew.sh) and find the installation command. It typically looks like this:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Let’s break down this command:
/bin/bash -c: This part executes the subsequent command using the bash shell.$(...): This is command substitution, meaning the output of the enclosed command will be used as an argument.curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh: This downloads the installation script from the Homebrew GitHub repository.curl: A command-line tool for transferring data with URLs.-f: Fail silently (no output on HTTP errors).-s: Silent or quiet mode.-S: Show error message if it fails.-L: Follow redirects.
When you execute this command, Homebrew will perform several checks to ensure your system is ready. It will inform you about what it’s going to do, including creating directories and installing necessary components. You will be prompted to press RETURN (or Enter) to continue and may be asked for your administrator password to make system-level changes.
Step 3: Verify the Installation
After the installation script completes, it’s crucial to verify that Homebrew has been installed correctly and that your system can find the brew command.
Open a new terminal window or tab (to ensure your shell environment picks up the new PATH settings) and run:
brew --version
If Homebrew is installed correctly, you should see the installed version number printed in your terminal. For example:
Homebrew 3.6.15
Homebrew/homebrew-core (git revision 0f23456789abcdef0123456789abcdef0123456789)
Homebrew/homebrew-cask (git revision 1234567890abcdef1234567890abcdef1234567890)
Step 4: Update Homebrew (and Formulas)
It’s good practice to update Homebrew and its formula definitions immediately after installation. This ensures you have access to the latest package information and any bug fixes.
Run the following command:
brew update
This command fetches the latest version of Homebrew itself and updates the local list of available packages (formulas) from the remote repositories.
Step 5: Configure Your PATH (If Necessary)
In most cases, the Homebrew installer automatically configures your system’s PATH environment variable to include the Homebrew executables. However, if brew --version still doesn’t work after opening a new terminal, or if you encounter issues with commands not being found, you might need to manually add Homebrew to your PATH.
Homebrew installs executables in /usr/local/bin (on older macOS) or in a specific location under /opt/homebrew/bin (on Apple Silicon Macs). The installation script usually adds a line to your shell profile file (like .zshrc or .bash_profile) to achieve this.
To check if it’s set up, you can look for lines related to Homebrew in your shell’s configuration file. For zsh (the default shell on recent macOS versions), this is typically ~/.zshrc:
cat ~/.zshrc
Look for lines similar to:
# Add Homebrew to your PATH
eval "$(/opt/homebrew/bin/brew shellenv)"
If these lines are missing, you can add them manually. First, determine your Homebrew prefix:
- Apple Silicon Macs:
/opt/homebrew - Intel Macs:
/usr/local
Then, add the following line to your ~/.zshrc (or ~/.bash_profile if you’re using bash) using a text editor like nano or vim:
# For Apple Silicon
eval "$(/opt/homebrew/bin/brew shellenv)"
# Or for Intel Macs
eval "$(/usr/local/bin/brew shellenv)"
After saving the file, source it to apply the changes to your current terminal session:
source ~/.zshrc # Or source ~/.bash_profile
Then, try brew --version again.
Installing Software with Homebrew
Now that Homebrew is installed and configured, you can start installing software. The basic command for installing a package is brew install.
Finding Packages
Before installing, you might want to search for available packages.
To search for a package:
brew search <package_name>
For example, to search for the wget utility:

brew search wget
This will list all packages that match your search query.
Installing a Package
To install a specific package, use the brew install command followed by the package name.
brew install <package_name>
For example, to install wget:
brew install wget
Homebrew will download the necessary files, compile them if required, and install wget and any of its dependencies.
Updating and Upgrading Packages
Homebrew makes it easy to keep your installed software up-to-date.
brew update: This command fetches the latest information about available packages from the repositories. It does not upgrade your installed packages.brew upgrade: This command upgrades all outdated installed packages to their latest versions.
It’s a common practice to run brew update followed by brew upgrade periodically to ensure all your software is current.
You can also upgrade a specific package:
brew upgrade <package_name>
Uninstalling Packages
If you no longer need a package installed via Homebrew, you can uninstall it.
brew uninstall <package_name>
For example, to uninstall wget:
brew uninstall wget
Homebrew will remove the package and its associated files.
Cleaning Up
Over time, Homebrew may leave behind old versions of installed packages or cached downloads. You can clean these up to free up disk space.
-
brew cleanup: This command removes outdated downloads for formulae and casks. It’s generally safe to run regularly.brew cleanup -
brew doctor: This command checks your Homebrew setup for potential problems and offers advice on how to fix them. It’s useful for diagnosing issues.brew doctor
Advanced Homebrew Usage
Homebrew offers more than just basic installation. It supports different types of installations and management strategies.
Homebrew Cask
Homebrew Cask extends Homebrew to support the installation of GUI applications (macOS applications with .app bundles) and other non-command-line software. This includes applications like Google Chrome, Visual Studio Code, VLC media player, and many others.
To install a cask application, you use brew install --cask:
brew install --cask <cask_name>
For example, to install Visual Studio Code:
brew install --cask visual-studio-code
To search for casks:
brew search --cask <application_name>
Taps
Taps are Git repositories that contain Homebrew formulas. Homebrew automatically taps the main homebrew/core repository. You can tap other repositories to gain access to additional formulas that are not part of the core distribution.
To tap a repository:
brew tap <user>/<repository>
For example, if a third-party developer provides formulas in a repository named my-formulas under their developer-username account on GitHub, you would tap it like this:
brew tap developer-username/my-formulas
After tapping, you can install formulas from that repository using the standard brew install command.
Pinning Formulas
Sometimes, you might need to keep a specific version of a formula installed, even when you run brew upgrade. This is useful if a newer version introduces compatibility issues or regressions. You can “pin” a formula to prevent it from being upgraded.
First, install the desired version of the formula. Then, pin it:
brew pin <formula_name>
To unpin a formula and allow it to be upgraded again:
brew unpin <formula_name>
Kegs
In Homebrew terminology, a “keg” is a specific installation of a formula. When you install a package, Homebrew creates a directory (a keg) for it. Homebrew manages multiple versions of packages by keeping them in separate kegs. It then creates symbolic links from a common directory (/usr/local/opt or /opt/homebrew/opt) to the currently active keg for that formula.
Troubleshooting
Homebrew is generally very stable, but issues can arise. The brew doctor command is your first line of defense. If it reports problems, carefully read its recommendations. Common issues include:
- Permissions errors: Often related to incorrect ownership of Homebrew directories.
- Conflicting installations: Another package manager or manual installation might interfere.
- Corrupted downloads or builds: A failed download or compilation step.
Homebrew’s extensive documentation and active community on platforms like GitHub and Stack Overflow are invaluable resources for troubleshooting.

Conclusion
Homebrew is an indispensable tool for any developer or power user on macOS and Linux. By simplifying the installation and management of software, it allows you to focus on your work rather than the intricacies of setting up your development environment. Mastering Homebrew is a key step in becoming more efficient and productive with your command-line tools and applications. From its straightforward installation process to its powerful features like Cask and taps, Homebrew empowers users to easily access and manage a vast ecosystem of software.
