Zsh: command not found: brew
How to fix zsh: command not found: brew
. When Homebrew is not installed or the Zsh shell $PATH
is not set correctly. For Mac M1, M2, M3 or Mac Intel.
Here are likely reasons for this error:
- You need to restart your Terminal ("reset the shell").
- Homebrew is not installed.
- The
$PATH
setting is missing or incorrect.
This is the error you'll see:
$ brew ...
zsh: command not found: brew
This article explains the reasons for the error and provides a step-by-step process to fix the error. After fixing the error, you can use Homebrew to install software packages you might need. In addition to fixing problems with Homebrew, this mac.install.guide website provides in-depth, up-to-date instructions for setting up a software development environment, including updating macOS, configuring Git, installing Xcode Command Line Tools for Apple's missing development tools, useful AI development tools, and programming languages. Take time to see all that's here.
Before you get started
You'll need a terminal application to fix the error. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.
Why you see 'zsh: command not found: brew'
You are trying to run Homebrew in the Mac Terminal. Homebrew is used for installing command line software. The Terminal interprets commands using the Zsh shell. The error messages shows that the Zsh shell cannot find Homebrew's brew
command.
Here is what went wrong:
- You may be following instructions that assume you have installed Homebrew previously but you didn't.
- Maybe you installed Homebrew previously but it is now missing.
- You need to restart the Terminal after installing Homebrew and setting the
$PATH
. - Most likely:
$PATH
is not set in a~/.zprofile
or~/.zshrc
configuration file. Without a correct$PATH
, the shell cannot find thebrew
command.
Here are the steps to take to fix the error.
Restart your Terminal
Just to rule out the simplest possible problem, quit the Terminal application and launch the Terminal again. Then try:
$ brew doctor
It's an obvious solution but worth trying. You should see Your system is ready to brew.
If so, you set the $PATH
correctly but neglected to start a new shell session.
If you see zsh: command not found: brew
, read on.
Is Homebrew installed?
Let's check if Homebrew is available but the $PATH
is not set. It's also possible that Homebrew is not installed.
You can try running the command with its full path to find out if Homebrew is installed. On a Mac M1, M2, or M3 (Apple silicon), Homebrew is installed by default in the /opt/homebrew/bin
folder. We'll try entering the brew
command with its full file path.
$ /opt/homebrew/bin/brew doctor
Your system is ready to brew.
You are trying brew doctor
with the full path to the M1, M2, or M3 brew
executable file to check if it runs.
Have you got an older Mac Intel machine? Homebrew installs itself into the /usr/local/bin
directory, which is configured by macOS default with the correct $PATH
environment variable. Try /usr/local/bin/brew doctor
to find out if "Your system is ready to brew" if you have an older Mac.
For both newer and older Macs, if you see Your system is ready to brew
when you provide the full path, Homebrew is available but the $PATH
is not set correctly. See the next section to check the $PATH
setting.
In the unusual case that you see zsh: command not found: brew
, with a correct $PATH
setting and Homebrew files in /opt/homebrew/bin
(for Apple M1, M2, or M3) or /usr/local/bin
(for macOS Intel), you can try reinstalling Homebrew. Uninstall Homebrew and then go to Install Homebrew.
Check the $PATH
If you provide the full path to the Mac brew
executable file and see Your system is ready to brew
but you don't see it unless you provide the full path, check the $PATH
setting. Try:
$ echo $PATH
...
The $PATH
should contain /opt/homebrew/bin
(for Apple M1, M2, or M3) or /usr/local/bin
(for macOS Intel). It should be among the highest priority directories, in a left-most position.
Setting the M1, M2, or M3 $PATH
On Mac M1, M2, or M3 (Apple silicon), Homebrew requires a $PATH
setting.
The $PATH
environment variable determines the directories the shell searches for executable files. The $PATH
is typically set in the ~/.zprofile
file. See the guide Mac PATH for instructions. The article .zshrc or .zprofile explains which configuration file to use.
There are two ways to set the $PATH
for Homebrew for Mac M1, M2, or M3 (Apple silicon).
Use brew shellenv to set $PATH
Homebrew provides instructions to use a supplied shell script to set the $PATH
variable. In the ~/.zprofile
file or ~/.zshrc
file, you should see this:
eval "$(/opt/homebrew/bin/brew shellenv)"
From the command line, try running shellenv
and check the response:
$ /opt/homebrew/bin/brew shellenv
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
If you don't see a similar response, it's likely that Homebrew is not installed. See the guide to Install Homebrew.
Set $PATH
directly
Not everyone follows the official Homebrew instructions to run shellenv
from a configuration file. You may have edited a configuration file to set the $PATH
directly.
These are the two zsh shell initialization files that are commonly used to set environment variables. $PATH
is typically set in either:
~/.zshrc
(Zsh Run Control): This file is the primary configuration file for user-specific shell customizations, such as setting command aliases and adjusting the shell prompt.~/.zprofile
(Zsh Profile): This file is read only on login. It's ideal for commands that should be executed only once when a terminal window is opened, such as setting the$PATH
environment variable.
The tilde ~/
means the .zshrc
or ~/.zprofile
file is found in your user home directory. If you are a user on a new Mac, you won't find these files. See the guide Shell Configuration for instructions about how to create, find and open the shell configuration files.
Check the ~/.zprofile
file or ~/.zshrc
file and you might see something like this:
eval "$(/opt/homebrew/bin/brew shellenv)"
or
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH
It's best to set the $PATH
variable with Homebrew's recommended shellenv
. See the guide Install Homebrew for instructions.
Resources
If you are starting with programming on the Mac, see Mac Terminal for basic concepts and How to Open Terminal in Mac. Also see the guide Shell Configuration. The article .zshrc or .zprofile explains which configuration file to use.
You also can learn more about the Homebrew package manager.
What's next
The Mac Install Guide website contains all the instructions you need to set up your Mac as a development environment for programming.
Take a moment to tell me What do you want to do next? so I know what else you need.