Have you just upgraded your Mac, switched to the ZSH shell, and now your beloved brew command has vanished into thin air? That frustrating “zsh: command not found: brew” error can stop your productivity in its tracks. Don’t worry—you’re not alone. This is a common rite of passage for Mac power users.
In this comprehensive, step-by-step guide, we’ll not only fix the “Brew Command Not Found” error on macOS with ZSH but also explore why it happens, how Homebrew actually works, and how to fortify your setup to prevent future issues. By the end, you’ll have a deeper understanding of your Mac’s terminal environment than ever before.
Understanding Why This Error Happens
Before we dive into the fixes, let’s understand the root cause. The error isn’t that Homebrew was deleted (though it could be). It’s almost always a path issue.
- What is ZSH? Z Shell (ZSH) is the default shell on macOS since Catalina (10.15). It replaced the older Bash shell. A shell is a command-line interpreter, and each has its own configuration files (like
~/.zshrcfor ZSH). - What is your PATH? The
PATHis a list of directories your shell searches through when you type a command likebrew. When you get a “command not found” error, it means the shell looked through every folder in yourPATHand couldn’t find an executable file namedbrew. - The Disconnect: Homebrew installs itself into
/usr/local/bin(on Intel Macs) or/opt/homebrew/bin(on Apple Silicon M1/M2/M3 Macs). For your ZSH shell to know about it, this directory must be listed in yourPATHvariable, which is set in your~/.zshrcfile.
The most common scenario is that you had Homebrew working under the old Bash shell, but your PATH was never correctly migrated to your new ZSH configuration.
Step-by-Step Solutions to Fix “Brew Command Not Found”
Follow these solutions in order. Start with Diagnosis, then try Solution A, and proceed if needed.
Step 0: Diagnosis – Check Your Current Setup
First, let’s gather information. Open your Terminal and run these commands:
- Check your shell:
echo $SHELL. It should return/bin/zsh. If it says/bin/bash, you might be using the wrong guide, or you can switch to ZSH withchsh -s /bin/zsh. - Check your current PATH:
echo $PATH. Look for either/opt/homebrew/bin(Apple Silicon) or/usr/local/bin(Intel) in the output. If you don’t see it, that’s the problem. - Check if Homebrew is actually installed: Look for the Homebrew directory.
- Apple Silicon Mac:
ls /opt/homebrew - Intel Mac:
ls /usr/local/Homebrew
If you see abinfolder inside, Homebrew is likely installed but not on your PATH.
- Apple Silicon Mac:
Solution A: The Quick PATH Fix (For Existing Installations)
If Homebrew is installed but not on your PATH, this is the fastest fix.
- Open your ZSH configuration file in a text editor. You can use Nano directly in the terminal:
nano ~/.zshrc - At the very top or bottom of the file, add the appropriate line for your Mac:
- For Apple Silicon (M1/M2/M3) Macs:
export PATH=/opt/homebrew/bin:$PATH - For Intel Macs:
export PATH=/usr/local/bin:$PATHThe
$PATHpart preserves your existing PATH. The new directory is added to the front, ensuring it’s checked first.
- For Apple Silicon (M1/M2/M3) Macs:
- Save the file:
- In Nano, press
Ctrl + O, thenEnter, thenCtrl + Xto exit.
- In Nano, press
- Reload your ZSH configuration for the changes to take effect in your current terminal session:
source ~/.zshrc - Test it:
brew --version. You should now see the version number.
Solution B: Reinstall Homebrew (The Nuclear Option)
If Solution A didn’t work, or if you suspect Homebrew is corrupted, a fresh install is best. Warning: This does not remove your existing formulas (apps) installed via brew, but it’s good to be cautious.
-
First, uninstall the existing Homebrew (if any). Run the official uninstall script from the Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"Follow the prompts. It will list what it will remove. For Intel Macs, it may ask for your sudo password to remove the
/usr/local/Homebrewdirectory. - Install Homebrew fresh using the official script. The script is now smart enough to detect your architecture and install to the correct location.


/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - CRITICAL FINAL STEP: The installer will output a message with two commands under the heading “Next steps.” They will look exactly like this (for Apple Silicon):
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc eval "$(/opt/homebrew/bin/brew shellenv)"You must run these commands. The first adds the correct Homebrew initialization to your
~/.zshrcfile, and the second activates it for your current session. - Close and reopen your Terminal, or run
source ~/.zshrc. Then test withbrew --version.
Solution C: The “Brew Shellenv” Method (The Most Robust)
This is the modern, recommended way and is what the installer suggests. It uses brew shellenv to dynamically generate the correct PATH settings. If you have a messy ~/.zshrc or multiple shell configurations, this is the cleanest approach.
- Open
~/.zshrc:nano ~/.zshrc - Remove any old manual Homebrew PATH lines you added earlier (like
export PATH=/opt/homebrew/bin:$PATH). - Add this single line:
eval "$(brew shellenv)"Important: This line must be placed after any tools that might themselves manage your PATH, like Conda (for Python) or NVM (for Node.js).
- Save and close the file (
Ctrl+O,Enter,Ctrl+X). - However, if
brewisn’t found yet, you can’t runbrew shellenv. You need to temporarily add the path manually to run it once. Run these two commands directly in your terminal:
For Apple Silicon:export PATH=/opt/homebrew/bin:$PATH eval "$(brew shellenv)"Now, run
brew --versionto confirm it works. Then, add theeval "$(brew shellenv)"line to your~/.zshrcas described above for a permanent fix.
Advanced Troubleshooting & Pro Tips
- Multiple Configuration Files: ZSH can load files from
~/.zshenv,~/.zprofile,~/.zshrc, and~/.zlogin. If you have a complex setup, ensure your Homebrew eval line is in the right file (~/.zshrcis the standard). - Conflicts with Other Tools: If you use Conda or NVM, their initialization scripts often manipulate the PATH. Place the
eval "$(brew shellenv)"line after these initializations in your~/.zshrcto ensure brew-managed tools take precedence when you want them to. - Check for Typos: A simple typo in
~/.zshrc(likeexport PTH=...) can break everything. Double-check your syntax. - The
whichCommand: Usewhich brewto tell you the full path of thebrewcommand that your shell would use. If it returns nothing, brew is not in your PATH.
How to Prevent This Problem in the Future
- Backup Your Dotfiles: Use a version control system like Git to manage your
~/.zshrcand other configuration files (.gitconfig,.vimrc, etc.). Store them on GitHub. This makes migration to a new Mac effortless. I personally use a bare Git repository to manage my dotfiles, a method popularized by developers. - Use a Framework: Consider using a ZSH framework like Oh My Zsh. It provides a robust, community-managed structure for your configuration and includes helpful plugins. It also makes managing your PATH and other settings more systematic.
- Document Your Setup: Keep a simple note of essential commands and modifications you make. This is invaluable when setting up a new environment.
Frequently Asked Questions (FAQ)
Q: Will reinstalling Homebrew delete all my installed apps (like node, python, wget)?
A: No. Your “cellar” (where compiled packages live) and “casks” (where GUI apps are installed) are kept in separate directories (/opt/homebrew/Cellar and /opt/homebrew/Caskroom on Apple Silicon). The uninstall script typically does not touch these. However, after a fresh install, run brew doctor to check the state of your packages.
Q: What’s the difference between /usr/local/bin and /opt/homebrew/bin?
A: /usr/local is the traditional Unix location for locally installed software on multi-user systems. /opt is for “optional” add-on software packages. Apple chose /opt/homebrew for Apple Silicon to avoid any potential conflicts with legacy Intel software and to maintain a clean separation.
Q: I’m getting permission errors (Error: Permission denied @ dir_s_mkdir). What should I do?
A: This usually means the ownership of the Homebrew directories is wrong. Homebrew requires certain directories to be owned by your user, not root. The command to fix this is:
sudo chown -R $(whoami) $(brew --prefix)/*
If `brew` isn't found, use the full path: for Apple Silicon, `sudo chown -R $(whoami) /opt/homebrew/*`.
Q: Is it safe to edit the ~/.zshrc file?
A: Absolutely. It’s a plain text file meant for user customization. The worst that can happen is you cause a syntax error that breaks your terminal session. You can always open a new terminal window or edit the file using a graphical text editor if your terminal becomes unresponsive.
Conclusion
Fixing the “brew command not found” error on macOS with ZSH almost always boils down to ensuring the correct Homebrew bin directory is in your shell’s PATH via the ~/.zshrc configuration file. The modern, most reliable method is to use the eval "$(brew shellenv)" command as provided by the Homebrew installer itself.
Remember, this minor hiccup is an opportunity to understand the powerful tools at your fingertips. By mastering your shell environment, you unlock greater control and efficiency on your Mac. Now that brew is back, go ahead and install that new tool you’ve been meaning to try—your system is ready.

