Software & OS

Homebrew Basics: Install, Use and Update brew on Mac and Linux

Homebrew is a package manager for macOS and Linux: install it with /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)", then install software with brew install <name>. Keep everything current with brew update followed by brew upgrade.

What Homebrew is (formulae, casks and the prefix)

Homebrew installs software into its own directory, called the prefix, and never writes files outside it. Each package goes into a versioned folder in the Cellar, and Homebrew links its files into the prefix so they appear on your PATH. The prefix depends on the machine:

MachineHomebrew prefix
Mac with Apple silicon/opt/homebrew
Mac with an Intel processor/usr/local
Linux and WSL/home/linuxbrew/.linuxbrew

There are two kinds of package:

  • Formulae: command-line tools, libraries and services, such as git, wget, node or postgresql. Usually installed as precompiled "bottles"; built from source when no bottle exists for your system.
  • Casks: prebuilt apps, fonts and plugins from their developers, such as a browser or code editor.

Run brew --prefix to print your install path.

How to install Homebrew

Check the requirements first (as of November 2026)

  • macOS: Homebrew's documentation lists macOS Sequoia (15) or newer on an Apple silicon Mac as the supported setup. Intel Macs are a "Tier 3" configuration, and macOS 11 to 14 are unsupported but may work. macOS 10.15 and older can't run current Homebrew at all.
  • Command Line Tools for Xcode are needed when a formula has to be built from source. The installer offers to install them.
  • bash to run the installer. The one-liner calls /bin/bash explicitly, so it works even if your login shell is zsh.

Run the installer

Paste this into Terminal (or a Linux or WSL shell), exactly as published on brew.sh:

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

The script explains what it will do and pauses before doing it. It may ask for your administrator password during setup; after that, routine formula installs don't need elevated privileges.

Add brew to your shell (fixes "command not found")

On Apple silicon and Linux the prefix is not on your PATH by default. Add a line like this to your shell profile. For zsh, the default shell on macOS:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

On Linux use /home/linuxbrew/.linuxbrew/bin/brew and ~/.bashrc. Homebrew's docs are blunt that without the shellenv line Homebrew won't work properly. brew shellenv just prints the export statements that set PATH and related variables; for how profiles and PATH work, see how to set environment variables.

Then check the install:

brew --version
brew doctor

brew doctor checks your system for potential problems and exits with a non-zero status if it finds any, listing each one with a suggested fix.

The Homebrew commands you'll use most

TaskCommand
Search by namebrew search wget
See details before installingbrew info wget
Install a formulabrew install wget
Install an app (cask)brew install --cask firefox
List what's installedbrew list
List only what you installed on purposebrew leaves
Uninstallbrew uninstall wget
Remove dependencies nothing needs any morebrew autoremove
What depends on a packagebrew uses --installed openssl@3
What a package depends onbrew deps wget

brew search is a substring search over formula and cask names, so brew search python lists every package with "python" in its name.

How to update Homebrew and your packages

Two different commands, often confused:

  • brew update fetches the newest version of Homebrew itself and the latest package definitions. It doesn't change any installed software.
  • brew upgrade upgrades installed packages that are outdated and not pinned. brew upgrade wget upgrades just one.
brew update
brew outdated
brew upgrade

brew outdated shows what would change before you commit to it. Homebrew also auto-updates before brew install, brew upgrade and brew tap; by default it does this at most once every 24 hours (HOMEBREW_AUTO_UPDATE_SECS, default 86400). To switch that off, add export HOMEBREW_NO_AUTO_UPDATE=1 to your profile.

Upgrading one package can upgrade several others. The FAQ explains that Homebrew only tests the latest version of each formula against the latest versions of its dependencies, because "that's the only combination of formulae we test".

Keep a package at its current version (pin)

brew pin postgresql@16
brew unpin postgresql@16

A pinned package is skipped by brew upgrade. For casks, the FAQ notes that an app's own built-in updater may still update it. If you need a specific major version long-term, install a versioned formula such as postgresql@16 or [email protected] where one exists, rather than pinning the unversioned one forever.

Free up disk space with brew cleanup

brew cleanup removes old versions of installed formulae, stale lock files and outdated downloads. Downloads older than 120 days are removed by default. Homebrew already runs a cleanup for the affected packages after each install, upgrade and reinstall, and cleans everything every 30 days, unless you set HOMEBREW_NO_INSTALL_CLEANUP. To see what it would delete first:

brew cleanup --dry-run

Background services (databases, web servers)

Formulae such as databases can run as background services. brew services manages them with launchd on macOS and systemd on Linux:

brew services list
brew services start postgresql@16
brew services stop postgresql@16

brew services run starts a service without registering it to start at login.

Recreate your setup on a new Mac (Brewfile)

brew bundle dump writes every installed formula, cask and tap into a Brewfile in the current directory. On another machine, after installing Homebrew:

brew bundle dump          # on the old machine
brew bundle install       # on the new machine, in the folder with the Brewfile

brew bundle install installs (and by default upgrades) everything listed in the Brewfile. The Brewfile is a plain text file, so you can keep it in a dotfiles repository.

If brew misbehaves

  • zsh: command not found: brew: the shellenv line is missing from your profile or the profile hasn't been reloaded. Open a new Terminal window after adding it.
  • Permission errors in the prefix: Homebrew expects the prefix to be owned by your user. Don't use sudo with brew; run brew doctor and follow what it reports.
  • brew --prefix prints /usr/local on an Apple silicon Mac: you are running the Intel copy of Homebrew, not the native one. The default prefix for Apple silicon is /opt/homebrew.

Homebrew is also a common way to install local AI tools on a Mac; see how to run an LLM on Apple silicon. On Linux, your distribution's own package manager is usually the first choice for system software; see apt vs dnf.

Frequently asked questions

Should I use sudo with brew?
No. Homebrew is designed to install packages as your own user into its prefix, and its FAQ explains that upstream build scripts should not have unrestricted system access. A few casks and system services ask for an administrator password themselves when they need it.
Why does brew upgrade one package upgrade a lot of others?
Homebrew only tests the latest version of each formula together with the latest versions of its dependencies. Upgrading one package therefore also upgrades its outdated dependencies and the formulae that depend on it, which can pull in big shared packages such as python or openssl.
Can I use Homebrew on Windows?
Not natively. Homebrew runs on macOS and Linux, and its homepage says the install command also works in WSL, the Windows Subsystem for Linux. Inside WSL it installs Linux packages into /home/linuxbrew/.linuxbrew, not Windows apps.
How do I stop Homebrew from updating every time I install something?
Homebrew refreshes its package list automatically before commands such as brew install and brew upgrade, by default at most once every 24 hours. Set export HOMEBREW_NO_AUTO_UPDATE=1 in your shell profile to turn that off, and run brew update yourself when you want new versions.
How do I uninstall Homebrew?
Homebrew's FAQ points to the uninstall script in the Homebrew/install repository on GitHub. Run it the same way as the install script, then remove the brew shellenv line from your shell profile.

Sources