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:
ls /opt/homebrew/bin/brewIf 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:
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~/.zprofileas 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~/.bashrcor~/.zshrc(Linux). On a server, apt is usually the better tool (why).
Which message do you see?
| Message | Where | Cause and fix |
|---|---|---|
zsh: command not found: brew | macOS Terminal, zsh on Linux | Not installed, or no shellenv line: find it, Apple Silicon |
bash: brew: command not found or -bash: brew: command not found | bash, an SSH login | The line is missing from the bash file: macOS bash, Linux |
bash: line 1: brew: command not found | ssh HOST 'brew …', scripts, CI steps | A non-interactive shell skips ~/.bashrc: fix |
/bin/sh: 1: brew: not found | cron, Dockerfile RUN on Debian or Ubuntu | No startup files read there: CI and Docker |
fish: Unknown command: brew | fish | fish line |
/Users/USER/.zprofile:2: no such file or directory: /opt/homebrew/bin/brew | Every new Terminal window | The 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 Rosetta | Intel 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 VPS | sudo and root |
sudo: brew: command not found | sudo brew … on Linux | sudo and root |
Is Homebrew installed, and where?
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/nulluname -mprintsarm64on Apple Silicon andx86_64on an Intel Mac. On Linux,aarch64orx86_64; Homebrew’s path is the same for both.lsprints thebrewthat exists. No output means Homebrew is not installed: run the installer from brew.sh as your normal user, not with sudo.grepshows which startup file loads Homebrew, and from which prefix. A line with/opt/homebrewon an Intel Mac, or/usr/localon Apple Silicon, is copied from the wrong guide. It printsno such file or directorywith the file name and line number in every new window. Change the path to thebrewthatlsfound.- Both found, and a new window still fails? A later line resets PATH, typically an
export PATH=…without$PATHin it.grep -n 'PATH=' ~/.zprofile ~/.zshrcshows it: add:$PATHto 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
echo 'eval "$(/opt/homebrew/bin/brew shellenv bash)"' >> ~/.bash_profileecho 'eval "$(/opt/homebrew/bin/brew shellenv fish)"' >> ~/.config/fish/config.fishKeep 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:
/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:
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:
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 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 installs | Everyone: files land in /usr/bin, on the PATH of sudo, cron and systemd | Shells that load the shellenv line; root is refused |
| Security fixes | From the distribution's security archive, automatic with unattended-upgrades | When you run brew upgrade |
| Versions | Fixed per release, with fixes backported | The newest upstream release |
| Libraries | Shared with the system | Its own copies, such as OpenSSL |
| Use it for | Services and anything other users or jobs run | A 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.
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:
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
command -v brew
brew --version
brew doctorcommand -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.