‘Brew Command Not Found’ Error on Mac
I’ve previously written about how to install Homebrew on your Mac. Homebrew for Mac is an open-source package manager that provides a convenient way to install, update, and manage various software packages and utilities from the command line.
While using Homebrew, you may run into a command not found error. The error message says zsh: command not found: brew, as you can see in the screenshot below. There can be a few reasons why you may see this error which happens when zsh is unable to find the brew binary. This can occur if your Homebrew installation is corrupt, nonexistent, or there is something wrong with your $PATH. In this article, we will cover several steps to resolve this issue.
Steps to fix the zsh brew command not found error
- Restart Terminal: Quit Terminal and try again. Doing so will reset the shell and this may fix the issue.
- Run brew doctor: Executing the following command will check if everything is up to date and working. Open Terminal and enter the following code:
brew doctor
You will see the following message saying your system is ready to brew if brew is good and running:
If you still see the not found error, keep reading.
- Reinstall Homebrew: Open Terminal on your Mac and execute the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This will reinstall Homebrew. Reinstalling it will fix the corrupt files if this is the issue. Test brew again; do you still get the command not found error?
- Add a new PATH: This will fix the issue if the PATH is missing or incorrect. Execute the following command:
export PATH="/opt/homebrew/bin:$PATH"
- Are you an Oh My Zsh user? Oh My Zsh is an open source Zsh package. If your brew problem started after installing Oh My Zsh, try adding the following line to your .zshrc file by running the following command:
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zshrc
After this, try running the brew doctor command again.
Related articles