Catalog / Homebrew Cheat Sheet

Homebrew Cheat Sheet

A comprehensive guide to Homebrew, the package manager for macOS. This cheat sheet covers installation, basic commands, package management, and troubleshooting.

Installation and Setup

Installation

To install Homebrew, open your terminal and run the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This script will guide you through the installation process. Follow the prompts, and enter your password if required.

Basic Setup

After installation, it’s important to add Homebrew to your PATH so that you can run brew commands from any terminal location.

Add these lines to your .zshrc or .bashrc file:

export PATH="/opt/homebrew/bin:$PATH"

Then, apply the changes to your current session:

source ~/.zshrc  # or source ~/.bashrc

Alternatively, for interactive setup in zsh, run:

eval "$(/opt/homebrew/bin/brew shellenv)"

Verify Installation

To ensure Homebrew is installed correctly, run:

brew doctor

This command will diagnose common issues and provide solutions.

If any problems are reported, follow the suggested steps to resolve them before proceeding.

Package Management

Installing Packages

brew install <package_name>

Installs the specified package.

Example:

brew install git

brew reinstall <package_name>

Reinstalls the specified package. Useful for fixing broken installations.

Example:

brew reinstall git

brew install <formula>@<version>

Installs a specific version of a formula.

Example:

brew install node@16

Updating Packages

brew update

Updates Homebrew’s package list.

brew upgrade

Upgrades all outdated packages.

brew upgrade <package_name>

Upgrades a specific package.

Example:

brew upgrade git

Removing Packages

brew uninstall <package_name>

Uninstalls the specified package.

Example:

brew uninstall git

brew cleanup

Removes old versions of packages from the Homebrew cache.

brew cleanup <package_name>

Removes old versions of specific packages from the Homebrew cache.

Example:

brew cleanup git

Brew Cask

Installing Applications

brew install --cask <application_name>

Installs the specified application using Brew Cask.

Example:

brew install --cask firefox

brew reinstall --cask <application_name>

Reinstalls the specified application using Brew Cask.

Example:

brew reinstall --cask firefox

Listing Installed Applications

To list all applications installed via Brew Cask, use the following command:

brew list --cask

Uninstalling Applications

brew uninstall --cask <application_name>

Uninstalls the specified application using Brew Cask.

Example:

brew uninstall --cask firefox

Advanced Usage

Searching for Packages

brew search <keyword>

Searches for packages containing the specified keyword.

Example:

brew search node

brew search /<regex>/

Searches using a regular expression.

Example:

brew search /^node.*/

Package Information

brew info <package_name>

Displays information about a package, including version, dependencies, and caveats.

Example:

brew info git

brew deps <package_name>

Lists the dependencies of a package.

Example:

brew deps node

Linking and Unlinking

brew link <package_name>

Links a package’s files into /usr/local.

Example:

brew link git

brew unlink <package_name>

Unlinks a package’s files from /usr/local.

Example:

brew unlink git