What the 'brew command not found' Error Means
The error brew: command not found (or zsh: command not found: brew in the zsh shell) appears when you try to run the brew command in the macOS terminal, but the system cannot find the executable file for that command. This means that the directory where brew is located is missing from the PATH environment variable. Homebrew is a package manager for macOS, and without it, you won't be able to install or update software via the terminal.
Typical full error text:
zsh: command not found: brew
or
bash: brew: command not found
Causes
- Homebrew is not installed. You are trying to use the
brewcommand, but the Homebrew program itself is missing from the system. - The path to Homebrew is not added to
PATH. Homebrew is installed (e.g., in/opt/homebrew/binfor Macs with Apple Silicon or/usr/local/binfor Intel), but this directory is not included in thePATHvariable, so the terminal doesn't know where to look for the executable. - The shell configuration file is not loading. The terminal uses a shell (e.g., zsh), but configuration files (such as
~/.zshrc), where thePATHis defined, are not loaded when starting a new session. - Homebrew installation is corrupted. The Homebrew files may have been damaged during installation or after a system update.
Method 1: Install Homebrew
If Homebrew is not installed, start by installing it. This is the simplest and most common solution.
- Open Terminal in macOS.
- Run the official installation command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Follow the on-screen instructions. The installer will ask for your administrator password and to press
Enterto confirm. - After installation completes, add Homebrew to your
PATHif the installer did not do it automatically. For Apple Silicon Macs (M1/M2/M3), run:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
For Intel Macs:
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
- Close and reopen the terminal or run
source ~/.zprofile.
Method 2: Add the Homebrew Path to the PATH Variable
If Homebrew is already installed but the brew command is not recognized, most likely the path to Homebrew is not in your PATH. This often happens after a macOS update or when using custom shell settings.
- Determine which shell you are using:
echo $SHELL
Typical output: /bin/zsh (default since macOS Catalina) or /bin/bash.
- Open the configuration file for your shell in a text editor (e.g., using
nanoorvim):- For zsh:
nano ~/.zshrc - For bash:
nano ~/.bash_profileornano ~/.bashrc
- For zsh:
- Add the following line to the end of the file with the path to Homebrew:
- For Apple Silicon (Macs with M1 chip and newer):
export PATH="/opt/homebrew/bin:$PATH" - For Intel:
export PATH="/usr/local/bin:$PATH"
- For Apple Silicon (Macs with M1 chip and newer):
- Save the file (in
nano:Ctrl + O, thenEnter, thenCtrl + X). - Apply the changes by running:
source ~/.zshrc # for zsh
or
source ~/.bash_profile # for bash
If you are unsure of the filename, you can simply restart the terminal.
- Verify that
brewis now available:
which brew
The output should show the path, e.g., /opt/homebrew/bin/brew.
Method 3: Check and Reload the Shell
Sometimes changes to PATH do not apply because the terminal is using a different shell or configuration files are loaded incorrectly.
- Ensure you edited the correct configuration file. macOS may use several files:
- For zsh:
~/.zshrc(for interactive shells) and~/.zprofile(for login shells). If~/.zshrcdid not work, try adding theexport PATHline to~/.zprofile. - For bash:
~/.bash_profile(for login shells) or~/.bashrc(for interactive non-login shells).
- For zsh:
- If you do not know which shell is active, run:
ps -p $$ -o comm=
This will show the current shell.
- After editing the file, fully restart the terminal (close the window and open it again) or run:
exec $SHELL -l
This restarts the shell as a login shell, loading all configurations.
- Check your
PATH:
echo $PATH
Ensure the Homebrew path (e.g., /opt/homebrew/bin) appears in the output.
Method 4: Reinstall Homebrew
If the previous methods did not help, the Homebrew installation may be corrupted. In this case, perform a full reinstall.
⚠️ Important: Reinstalling will remove all packages installed via Homebrew. Create a backup of your package list:
brew list > brew_backup.txt.
- Uninstall Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
- Ensure all files are removed:
sudo rm -rf /opt/homebrew # for Apple Silicon
sudo rm -rf /usr/local/Homebrew # for Intel
- Install Homebrew again, as described in Method 1.
Prevention
To avoid the error recurring:
- Always use the official Homebrew installation script. Do not download or move files manually.
- After installation, check your
PATH: runecho $PATHand ensure the Homebrew path (e.g.,/opt/homebrew/bin) is present. - Update Homebrew regularly:
brew updateandbrew upgrade. - If you change shells (e.g., from bash to zsh), ensure the configuration files for the new shell contain the
PATHsettings. - When updating macOS, check if the
PATHsettings were reset. Sometimes you need to re-add Homebrew to the configuration files.