How to Fix the homebrew installation problem “Zsh: command not found – brew”

Homebrew installation problem
The error zsh: command not found - brew
in macOS means that the Zsh shell (the default shell since macOS Catalina) can’t locate the brew
command, typically because Homebrew’s installation didn’t properly update your shell’s PATH environment variable.
Why This Happens
- PATH Issue: Homebrew installs to
/usr/local/bin
(Intel) or/opt/homebrew/bin
(Apple Silicon), but Zsh won’t find it unless that directory is in your PATH. - Incomplete Install: If the install script didn’t finish or you skipped adding the PATH, Zsh won’t recognize
brew
. - Shell Switch: If you recently changed shells (e.g., from Bash to Zsh), old configs might not carry over.
Here’s how to fix it step-by-step in the video and the following text:–
Steps to Fix “Zsh: command not found – brew”
1. Verify Homebrew Installation
- First, ensure Homebrew is actually installed:
- Open Terminal and run:
ls -l /usr/local/bin/brew # For Intel Macs
- Or for Apple Silicon Macs:
ls -l /opt/homebrew/bin/brew
- Open Terminal and run:
- If it returns a file path (e.g., a symlink), Homebrew is installed but not in your PATH. If it says “No such file or directory,” Homebrew isn’t installed—skip to Step 5 to install it.
2. Check Your Shell PATH
- Run:
echo $PATH
- Look for
/usr/local/bin
(Intel) or/opt/homebrew/bin
(Apple Silicon) in the output. If it’s missing, Zsh doesn’t know where to findbrew
.
3. Add Homebrew to Your PATH
- Determine your Mac’s architecture:
- Run
uname -m
: x86_64
= Intelarm64
= Apple Silicon
- Run
- Open your Zsh configuration file:
nano ~/.zshrc
- Add the appropriate line at the bottom:
- For Intel Macs:
export PATH="/usr/local/bin:$PATH"
- For Apple Silicon Macs:
export PATH="/opt/homebrew/bin:$PATH"
- For Intel Macs:
- Save the file (
Control + X
, thenY
, thenEnter
).
4. Apply the Changes
- Reload your Zsh configuration:
source ~/.zshrc
- Verify
brew
works:brew --version
- If it outputs a version (e.g., “Homebrew 4.x.x”), the issue is fixed.
5. Reinstall Homebrew (If Not Installed or Broken)
- If Step 1 showed Homebrew isn’t installed, or if it’s still not working:
- Install Homebrew fresh:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Homebrew fresh:
- Follow the on-screen instructions (e.g., enter your admin password).
- After installation, it should automatically suggest adding the PATH command to
~/.zshrc
. If not, manually add it as in Step 3.
6. Test and Troubleshoot
- Run:
brew doctor
- This checks for issues. If it warns about permissions or PATH problems, follow its advice (e.g.,
sudo chown $(whoami):admin /usr/local/Cellar
for Intel Macs). - If
brew
still fails, check permissions:ls -ld /usr/local/bin # Intel ls -ld /opt/homebrew/bin # Apple Silicon
- Ensure your user has access (e.g.,
drwxr-xr-x
with your username). Fix with:sudo chown -R $(whoami):admin /usr/local/bin # Intel sudo chown -R $(whoami):admin /opt/homebrew/bin # Apple Silicon