If you’re a regular Homebrew user, you’ll know what a convenient tool it is for installing packages using Terminal. You may also be baffled when you come across the error message ‘Brew command not found’ when you try to use Homebrew in a zsh shell in Terminal. It is usually the following: “zsh: command not found: brew”, and in this article, we will explain the possible causes of this error and show you how to fix them.
What is Homebrew?
Just in case you haven’t heard of it, Homebrew is a package management tool that allows you to install open source software on your Mac from the command line in Terminal. It’s an excellent way to, for example, install Git, so you can then ‘pull’ code from GitHub and install it on your Mac. Once you’ve installed Homebrew, packages can usually be installed with just one command.
Why does the ‘Brew command not found’ error appear on my Mac?
There are a few possible reasons the error message may appear, but they all have the same root cause: the zsh shell can’t find the brew binary to execute. That could be because there is something wrong with the $PATH (the variable that specifies where executable programs are located) or with the Homebrew installation.
How to fix ‘Brew command not found’ on your Mac
The simplest way to fix the ‘Brew command not found’ error is to reinstall Homebrew. To do that, follow the steps below.
- Open Terminal.
- Type or paste the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Press Return. You will see information in the Terminal window explaining what will be installed and where it will be installed.
- Press Return again.
- Type in your admin password and press Return.
- Wait for a message telling you the installation has finished.
- You can now try the brew command again to see if it works.
If the brew command not found error still appears after you have reinstalled Homebrew, the next step is to put brew in your zshrc path. To do that, open a new Terminal window and type or paste the command below followed by Return:
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
Next, use the command below to repair brew: brew doctor
If you see ‘Brew command not found’ after installing Oh My Zsh
If you have just installed Oh My Zsh to allow you to install plug-ins for Zsh and then see the ‘Brew command not found’ error, there is something else you can try. You can add a line to your zshrc file. The file lives in the root folder of your Home directory, but it is hidden. To see it, you can view hidden files or use Finder > Go > Go to Folder > ~/zshrc. Open it in Text Edit and add the line below. Then, save and close it.
eval $(/opt/homebrew/bin/brew shellenv)
Alternatively, you can use the command below in a Terminal window to add the line:
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zshrc
Next, run brew doctor again using the Terminal command: brew doctor
The error message ‘brew command not found’ means there is a problem with the installation of Homebrew on your Mac. Follow the steps above to fix it and get Homebrew running again.