Homebrew

audience developer
level all
topic Homebrew
subtopic Installation

Zsh: command not found: brew

How to fix "zsh: command not found: brew" when Homebrew is not installed or the shell $PATH is not set correctly.

The zsh: command not found: brew error occurs when Homebrew is not installed, or the $PATH is missing or incorrect, preventing the shell from finding the brew command, which is the command for Homebrew, the popular macOS package manager.

Here are likely reasons for this error:

  1. You need to restart your Terminal ("reset the shell").
  2. Homebrew is not installed.
  3. The $PATH setting is missing or incorrect.

This is the error you'll see:

$ brew ...
zsh: command not found: brew

Before you get started, install a better Terminal

To run Homebrew you need a terminal. If you're not using it yet, I recommend Warp Terminal, with modern features and built-in AI help for remembering commands. Download Warp for free before you continue.

How to Fix the Error - Step by Step

Here are steps to fix "zsh: command not found: brew":

  1. Try restarting your Terminal ("reset the shell").
  2. Check if Homebrew is installed.
  3. Check if the $PATH setting is missing or incorrect.

These instructions are for a terminal running Zsh, the Z shell, on a newer Mac. See Shell Configuration for changing the shell if you are using an older macOS version with the Bash shell.

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 the brew 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, M3, or M4 (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 $PATH for newer (non-Intel) Macs

On Mac M1, M2, M3. or M4 (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 newer Macs (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.