Homebrew Package Management Guide — Installation, Management, and Cask

What Is Homebrew?

Homebrew is the most widely used package manager for macOS (and Linux). Its official repository contains thousands of CLI tools and GUI applications, all installable, updatable, and removable with a single terminal command. CLI tools are categorized as Formulae, while GUI apps are called Casks.

This article covers Homebrew installation, Formula/Cask management, taps, and using Brewfile for environment backup/restore.

Installing Homebrew

Install Homebrew using the official install script. Xcode Command Line Tools are automatically installed along with it.

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

# Apple Silicon Macs (M1/M2/M3/M4) need PATH setup after installation
# Run the commands shown by the install script:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

# Verify installation
brew --version
# Sample output: Homebrew 4.4.10

# Diagnose system status
brew doctor
# Output: Your system is ready to brew.

Intel Macs install to /usr/local/, while Apple Silicon Macs install to /opt/homebrew/.

Formula (CLI Tool) Management

Formulae are CLI tools built from source or pre-compiled.

# Search for packages
brew search node
# Sample output:
# ==> Formulae
# node           node@20        node@22        nodenv
# ==> Casks
# nodebox

# View package info
brew info node
# Output: version, dependencies, install path, options, etc.

# Install packages
brew install git
brew install node
brew install python@3.12
brew install go

# List installed packages
brew list
# Output: ca-certificates gettext git libuv node openssl ...

# Detailed list (with versions)
brew list --versions
# Output:
# git 2.44.0
# node 22.12.0
# python@3.12 3.12.8

Cask (GUI App) Management

Cask manages macOS native apps (.app). Installing apps via Homebrew instead of the App Store makes update management more convenient.

# Install GUI apps
brew install --cask visual-studio-code
brew install --cask iterm2
brew install --cask docker
brew install --cask firefox
brew install --cask rectangle        # Window management tool
brew install --cask raycast          # Spotlight replacement

# List installed Casks
brew list --cask
# Output: docker firefox iterm2 visual-studio-code ...

# View Cask info
brew info --cask visual-studio-code
# Output: version, homepage, install path, etc.

# Remove Cask (uninstall app)
brew uninstall --cask firefox

Package Updates and Cleanup

# Update Homebrew itself
brew update
# Refreshes Formula/Cask definitions to latest

# Check for available updates
brew outdated
# Sample output:
# git (2.43.0) < 2.44.0
# node (22.11.0) < 22.12.0

# Upgrade a specific package
brew upgrade git

# Upgrade all packages
brew upgrade

# Clean up old versions (reclaim disk space)
brew cleanup
# Removes versions older than 30 days

# Preview what would be cleaned up
brew cleanup --dry-run
# Sample output: Would remove 1.2GB of old files

Taps (Third-Party Repositories)

Taps let you install packages from additional repositories not in the official Homebrew repository.

# Add a tap
brew tap hashicorp/tap       # HashiCorp tools (Terraform, etc.)
brew tap homebrew/cask-fonts  # Developer fonts

# Install packages from a tap
brew install hashicorp/tap/terraform
brew install --cask font-jetbrains-mono-nerd-font

# List registered taps
brew tap
# Output:
# hashicorp/tap
# homebrew/cask
# homebrew/cask-fonts
# homebrew/core

# Remove a tap
brew untap hashicorp/tap

Brewfile for Environment Backup/Restore

Brewfile manages the list of installed packages as a file. It enables fast restoration of an identical development environment on a new Mac.

# Export currently installed packages to Brewfile
brew bundle dump --file=~/Brewfile --force
# --force: overwrite existing file

The generated Brewfile looks like this:

# ~/Brewfile
# Tap repositories
tap "homebrew/cask-fonts"
tap "hashicorp/tap"

# CLI tools (Formulae)
brew "git"
brew "node"
brew "python@3.12"
brew "go"
brew "jq"
brew "wget"
brew "ripgrep"
brew "fzf"
brew "bat"                  # cat replacement (syntax highlighting)
brew "eza"                  # ls replacement (icons/colors)
brew "zoxide"               # cd replacement (smart navigation)
brew "lazygit"              # Git TUI client

# GUI apps (Casks)
cask "visual-studio-code"
cask "iterm2"
cask "docker"
cask "rectangle"
cask "raycast"
cask "arc"
cask "font-jetbrains-mono-nerd-font"

# Mac App Store apps (requires mas)
# mas "Xcode", id: 497799835
# mas "Magnet", id: 441258766
# Bulk install from Brewfile (on a new Mac)
brew bundle --file=~/Brewfile
# All taps, formulae, and casks are installed in order

# Check installation status
brew bundle check --file=~/Brewfile
# Output: The Brewfile's dependencies are satisfied.

# Find packages not in Brewfile (cleanup candidates)
brew bundle cleanup --file=~/Brewfile
# Lists packages not specified in Brewfile

# Remove packages not in Brewfile
brew bundle cleanup --file=~/Brewfile --force

Service Management

Manage background services (DBs, caches, etc.) installed via Homebrew.

# Install and start PostgreSQL service
brew install postgresql@16
brew services start postgresql@16

# List services
brew services list
# Sample output:
# Name           Status  User File
# postgresql@16  started user ~/Library/LaunchAgents/...

# Redis service management
brew install redis
brew services start redis    # Start (auto-starts on login)
brew services stop redis     # Stop
brew services restart redis  # Restart

# Run once (without auto-start)
brew services run redis

Practical Tips

  • Manage Brewfile with Git: Including Brewfile in your dotfiles repo means a new Mac setup is done with a single brew bundle
  • Prefer Cask: Installing apps via Cask instead of the App Store enables bulk updates with brew upgrade --cask
  • Weekly updates: Run brew update && brew upgrade && brew cleanup once a week to apply security patches
  • brew doctor: When problems arise, brew doctor diagnoses system status and provides solutions
  • Pin versions: If you need a specific version, brew pin node prevents upgrades
  • Apple Silicon compatibility: Most Formulae are built as ARM native. For the occasional case requiring Rosetta 2, install with arch -x86_64 brew install packagename

Was this article helpful?