Fixing "zsh: command not found: brew" on macOS
Encountering "zsh: command not found: brew" after installing Homebrew is a common issue, particularly on Apple Silicon Macs (M1/M2/M3/M4 chips) where the installation path differs from Intel-based Macs. This guide provides comprehensive solutions to resolve this problem and get Homebrew working correctly.
Why This Happens
Homebrew installs to different locations depending on your Mac's architecture:
- Intel Macs:
/usr/local/bin/ - Apple Silicon Macs (M1/M2/M3/M4):
/opt/homebrew/bin/
When your shell can't find the brew command, it means the Homebrew installation directory isn't in your shell's PATH environment variable.
Primary Solution: Add Homebrew to Your PATH
Step 1: Verify Homebrew Installation
First, ensure Homebrew is properly installed using the current installation method:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Step 2: Add Homebrew to Your Shell Configuration
For Apple Silicon Macs (M1/M2/M3/M4), add this to your ~/.zshrc file:
echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.zshrcFor Intel Macs, use this command instead:
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.zshrcStep 3: Apply the Changes
Either restart your terminal or run:
source ~/.zshrcStep 4: Verify Brew Works
Test that Homebrew is now accessible:
brew doctorYou should see: "Your system is ready to brew."
Alternative Method: Using Homebrew's Recommended Approach
After installation, Homebrew often provides specific instructions. Look for output similar to:
Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> ~/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"Run these commands exactly as shown to properly configure your environment.
PATH Order Matters
Ensure Homebrew paths come before system paths in your PATH variable. The correct order should be:
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbinAdvanced Troubleshooting
Check Installation Location
Verify where Homebrew is installed:
ls /opt/homebrew/bin/brew # Apple Silicon
ls /usr/local/bin/brew # IntelManual PATH Modification
If the echo commands don't work, manually edit your ~/.zshrc file:
nano ~/.zshrcAdd the appropriate export line (as shown above) to the file, save, and exit.
For Linux Users
On Ubuntu or other Linux systems, use Homebrew's recommended path:
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> ~/.zshrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"Terminal Configuration Check
INFO
If you recently force-quit Terminal or changed settings, check your Terminal preferences. Ensure "Shells open with" is set to "Default login shell" or "Command (complete path)" with /bin/zsh specified.
Verify Your Shell
Confirm zsh is your default shell:
echo $SHELLIf it's not zsh, change it with:
chsh -s /bin/zshConclusion
The "zsh: command not found: brew" error typically occurs because Homebrew's installation directory isn't in your PATH. By adding the appropriate path to your ~/.zshrc file—/opt/homebrew/bin for Apple Silicon Macs or /usr/local/bin for Intel Macs—you'll resolve this issue and have full access to Homebrew's package management capabilities.
After applying these changes, restart your terminal and run brew doctor to confirm everything is working correctly.