Troubleshooting

brew: command not found — fix Homebrew's PATH on Mac and Linux

zsh: command not found: brew means Homebrew's bin folder is not on your PATH. On Apple Silicon, add the brew shellenv line for /opt/homebrew to ~/.zprofile.

Published ~8 min read

Short answer: zsh: command not found: brew means Homebrew is not installed, or its bin directory is not on the PATH of this shell. On an Apple Silicon Mac that directory is /opt/homebrew/bin, and the installer cannot add it to the terminal window you ran it from. Check that Homebrew is there:

macOS · Apple Silicon
ls /opt/homebrew/bin/brew

If ls prints the path, run the three lines the installer shows under “Next steps”. The second makes the fix permanent, the third applies it to the open window:

macOS · Apple Silicon · zsh
echo >> ~/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv zsh)"

If ls reports No such file or directory, Homebrew is not installed in that place. Where it should be depends on the machine:

  • Apple Silicon Mac: /opt/homebrew, loaded from ~/.zprofile as above (details).
  • Intel Mac: /usr/local, which macOS already searches. The installer no longer sets up new Intel installs (why).
  • Linux and WSL: /home/linuxbrew/.linuxbrew, loaded from ~/.bashrc or ~/.zshrc (Linux). On a server, apt is usually the better tool (why).

Which message do you see?

MessageWhereCause and fix
zsh: command not found: brewmacOS Terminal, zsh on LinuxNot installed, or no shellenv line: find it, Apple Silicon
bash: brew: command not found or -bash: brew: command not foundbash, an SSH loginThe line is missing from the bash file: macOS bash, Linux
bash: line 1: brew: command not foundssh HOST 'brew …', scripts, CI stepsA non-interactive shell skips ~/.bashrc: fix
/bin/sh: 1: brew: not foundcron, Dockerfile RUN on Debian or UbuntuNo startup files read there: CI and Docker
fish: Unknown command: brewfishfish line
/Users/USER/.zprofile:2: no such file or directory: /opt/homebrew/bin/brewEvery new Terminal windowThe line points at a Homebrew that is not there: check the prefix
Homebrew on macOS is only supported on Apple Silicon processors!The installer, on an Intel Mac or under RosettaIntel Macs
Don't run this as root! or Error: Running Homebrew as root is extremely dangerous and no longer supported.Installer or brew as root, e.g. on a VPSsudo and root
sudo: brew: command not foundsudo brew … on Linuxsudo and root

Is Homebrew installed, and where?

macOS · Linux
uname -m
ls -l /opt/homebrew/bin/brew /usr/local/bin/brew /home/linuxbrew/.linuxbrew/bin/brew 2>/dev/null
grep -n 'brew shellenv' ~/.zprofile ~/.zshrc ~/.bash_profile ~/.bashrc 2>/dev/null
  • uname -m prints arm64 on Apple Silicon and x86_64 on an Intel Mac. On Linux, aarch64 or x86_64; Homebrew’s path is the same for both.
  • ls prints the brew that exists. No output means Homebrew is not installed: run the installer from brew.sh as your normal user, not with sudo.
  • grep shows which startup file loads Homebrew, and from which prefix. A line with /opt/homebrew on an Intel Mac, or /usr/local on Apple Silicon, is copied from the wrong guide. It prints no such file or directory with the file name and line number in every new window. Change the path to the brew that ls found.
  • Both found, and a new window still fails? A later line resets PATH, typically an export PATH=… without $PATH in it. grep -n 'PATH=' ~/.zprofile ~/.zshrc shows it: add :$PATH to the end of that value, or delete the line.

Apple Silicon: put /opt/homebrew on your PATH

The installer runs as a child process of your shell, and no child process can change its parent’s PATH. That is why the window you installed from does not find brew until you run the eval line there. When it has admin rights, the current installer also writes /etc/paths.d/homebrew, so macOS’s path_helper adds /opt/homebrew/bin to new Terminal windows even without the line. It appends it, though: Apple’s /usr/bin/git and /usr/bin/python3 still win over Homebrew’s. Older installs, and installs from an account without admin rights, have no such file at all.

The shellenv line fixes both. It puts /opt/homebrew/bin and /opt/homebrew/sbin at the front of PATH, sets HOMEBREW_PREFIX and INFOPATH, and adds Homebrew’s zsh completions. brew shellenv prints nothing when those two directories already lead PATH, so a second copy of the line does no harm. The zsh argument is what current installers print; an older line without it still works, and Homebrew then guesses the shell.

Why ~/.zprofile and not ~/.zshrc or ~/.zshenv

zsh reads ~/.zprofile in login shells, and Terminal opens a login shell in every new window. It reads it after /etc/zprofile, where macOS runs path_helper. ~/.zshrc works as well, because it is read later still. ~/.zshenv is the wrong place: it runs before path_helper, which then moves the system directories back in front of Homebrew’s.

bash and fish on a Mac

macOS · bash
echo 'eval "$(/opt/homebrew/bin/brew shellenv bash)"' >> ~/.bash_profile
macOS · fish
echo 'eval "$(/opt/homebrew/bin/brew shellenv fish)"' >> ~/.config/fish/config.fish

Keep the single quotes. They write the line as it is, so $(…) runs each time a shell starts. Then open a new window. Apps started from the Dock read none of these files, so a tool inside an editor or an AI app can still miss Homebrew. The npx guide’s section on apps shows how to give them a full path.

Intel Macs: /usr/local, and no new installs

On an Intel Mac, Homebrew lives in /usr/local/bin, which is on macOS’s default PATH. A working Intel install is therefore rarely “not found”; when brew is missing there, the install never finished. Since September 2026 the installer stops on Intel with Homebrew on macOS is only supported on Apple Silicon processors!, and the .pkg installer supports only Apple Silicon too. Existing Intel installs keep running as an unsupported Tier 3 setup. Homebrew no longer builds new bottles for them, so updated formulae may compile from source, and it plans to stop running on Intel in or after September 2027 (per its Support Tiers page, checked 12 Oct 2026). For a new setup on an Intel Mac, use MacPorts or the vendors’ own installers.

Moved from an Intel Mac with Migration Assistant? The old Homebrew may have come along in /usr/local, and your ~/.zprofile may still point there. Install a fresh Homebrew, which goes to /opt/homebrew. While the old copy still runs (it needs Rosetta), carry your formulae over with a Brewfile, then change the shellenv line to /opt/homebrew:

macOS · after migrating to Apple Silicon
/usr/local/bin/brew bundle dump --file="$HOME/Brewfile"
/opt/homebrew/bin/brew bundle install --file="$HOME/Brewfile"

Linux and WSL: /home/linuxbrew/.linuxbrew

On Linux the installer puts Homebrew in /home/linuxbrew/.linuxbrew, the prefix its prebuilt bottles are made for, and adds nothing to any PATH. For bash the line goes into ~/.bashrc; with zsh as your login shell, use ~/.zshrc and the argument zsh:

Linux · bash
echo >> ~/.bashrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"

Homebrew also expects a compiler and a few tools from the distribution. The installer stops without curl and git, so on a fresh server install these first:

Debian · Ubuntu
sudo apt-get install build-essential procps curl file git

“bash: line 1: brew: command not found” over SSH and in scripts

Your login shell finds brew, but ssh HOST 'brew upgrade', a deploy script or sudo -iu USER brew … does not. On Debian and Ubuntu, bash does read ~/.bashrc for commands run over SSH, but the stock ~/.bashrc starts with a case $- in block that returns at once when the shell is not interactive. The shellenv line sits at the end of the file and never runs. Call brew by its full path in those places, or move the line above that block:

ssh · scripts
ssh USER@SERVER_IP '/home/linuxbrew/.linuxbrew/bin/brew upgrade'

sudo and root

On Linux, sudo brew … fails with sudo: brew: command not found because sudo replaces your PATH with the secure_path from /etc/sudoers, which has no Homebrew in it. On a Mac, sudo keeps your PATH and finds brew, which then stops by itself. Do not work around either: Homebrew refuses root. The installer stops with Don't run this as root! (it allows root only inside containers and CI runners), and brew run as root by its full path ends with Error: Running Homebrew as root is extremely dangerous and no longer supported. Formulae install without sudo; the few casks that need admin rights ask for your password themselves. On a fresh VPS you are root, so create a normal user first and install Homebrew as that user.

On a server, apt is usually the better tool

apt (Debian, Ubuntu)Homebrew on Linux
Who can run what it installsEveryone: files land in /usr/bin, on the PATH of sudo, cron and systemdShells that load the shellenv line; root is refused
Security fixesFrom the distribution's security archive, automatic with unattended-upgradesWhen you run brew upgrade
VersionsFixed per release, with fixes backportedThe newest upstream release
LibrariesShared with the systemIts own copies, such as OpenSSL
Use it forServices and anything other users or jobs runA newer command-line tool for your own account

Before installing Homebrew on a server, run apt-cache policy PACKAGE: a Candidate line with a version number means apt can install it. Many projects also publish their own apt repository with current versions. If apt says it cannot find the package at all, see Unable to locate package.

CI and Docker

GitHub’s Ubuntu runners have Homebrew installed in /home/linuxbrew but not on the PATH, and an eval in one step is gone in the next. Add the directory to GITHUB_PATH, which puts it on the PATH of every later step in the job. GitHub’s macOS runners already have brew on the PATH.

GitHub Actions · Ubuntu runner, run step
echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH"

In a Dockerfile, each RUN line starts a fresh /bin/sh, so an eval does not carry over and the next line says /bin/sh: 1: brew: not found. Set the PATH for the whole image instead:

Dockerfile
ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}"

The same goes for cron: it reads no startup files, so give the job the full path to brew.

Check that it works

new terminal window
command -v brew
brew --version
brew doctor

command -v should print /opt/homebrew/bin/brew on Apple Silicon, /usr/local/bin/brew on Intel or /home/linuxbrew/.linuxbrew/bin/brew on Linux. brew doctor ends with Your system is ready to brew. when nothing is wrong, or lists what is. If a tool you installed with Homebrew is still “not found”, it may be keg-only, as versioned formulae such as node@24 are: installed, but not linked into bin. brew info FORMULA prints the directory to add. For the two tools people miss most, see git: command not found and npx: command not found.

Installed nvm with brew install nvm and the shell cannot find it? Homebrew installs only the script, not a command; see nvm: command not found.

Another tool missing, or PATH questions beyond Homebrew? See command not found: the three causes and the fix for every tool. If you are setting up a server rather than a Mac, a Debian VPS gives you root over SSH from the first boot, and apt covers most of what you would otherwise install with Homebrew.

Frequently asked

Why does my Mac say 'zsh: command not found: brew' after installing Homebrew?

On Apple Silicon, Homebrew lives in /opt/homebrew/bin, and the installer cannot change the PATH of the terminal it ran in. Run the lines it prints under Next steps: add eval "$(/opt/homebrew/bin/brew shellenv zsh)" to ~/.zprofile, then open a new Terminal window or run the same eval line once. If /opt/homebrew/bin/brew does not exist, Homebrew is not installed.

Where is Homebrew installed?

In /opt/homebrew on Apple Silicon Macs, /usr/local on Intel Macs, and /home/linuxbrew/.linuxbrew on Linux and WSL. The brew command is in the bin directory under that prefix, and brew --prefix prints the prefix once brew runs.

Can I still install Homebrew on an Intel Mac?

Not with the current installer: since September 2026 it stops with 'Homebrew on macOS is only supported on Apple Silicon processors!', and the .pkg installer supports only Apple Silicon too. Existing Intel installs keep working in /usr/local as an unsupported Tier 3 setup without new bottles, and Homebrew plans to stop running on Intel in or after September 2027. MacPorts is the usual alternative.

Related articles

All troubleshooting