Did you just install Homebrew, only to find that your Terminal won’t recognize brew commands? Homebrew is a versatile package manager for macOS or Linux. While installing it is pretty straightforward, there are a few key steps that are easy to overlook. Unfortunately, missing these steps will cause brew commands to fail, triggering a “zsh: command not found: brew” error. In this article, we’ll explain the usual reasons for this error and how to fix it.
How to Fix the Zsh: Command Not Found: Brew Error
This typically means that either Homebrew is not installed or that its path is not in your shell's configuration file. First, restart Terminal to refresh your session. If that doesn’t work, make sure Homebrew is actually installed . If it is, you need to add Homebrew's path to your .zprofile file.
Steps
Restarting Terminal
-
1Quit Terminal and restart it. In some cases, fixing this error is as simple as starting a new shell session. Typically, you need to restart the Terminal right after installing Homebrew in order for it to work correctly.
-
2Run the brew doctor command. Once Terminal restarts, run this command to check if Homebrew is working. If it is, you should see a message saying Your system is ready to brew .
- If your version of Homebrew is outdated, this command might trigger an update. If so, it may take a few minutes for the process to complete.
- If you see the zsh: command not found error after running brew doctor , that means Homebrew isn’t installed correctly or the $PATH hasn’t been set in the shell config file.
Setting the PATH
-
Determine Homebrew’s install location. After you install Homebrew, you’ll need to update your shell’s config file before you can run any brew commands. To run this command correctly, you’ll need to figure out the default path to Homebrew on your system. [2] X Research source
- If you have a Mac with an Apple Silicon chip (M1, M2, M3, or M4), the default install location is /opt/homebrew. [3] X Research source
- For Intel Macs, the default path is /usr/local.
- On Linux, it’s /home/linuxbrew/.linuxbrew.
-
2Update your shell’s config file with the correct Homebrew path. Typically, you can do this from within Terminal when you first install Homebrew. Right after installation, you’ll see a line in the Terminal window that says something like this:
- Next steps: - Add Homebrew to your PATH in /Users/$USER/.zprofile:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)- Copy and paste the line echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile into the Terminal window and press Return .
- The exact format of the line will depend on your system and Homebrew’s install location.
- Then, copy and paste eval $(/opt/homebrew/bin/brew shellenv) into Terminal and press Return again.
- Quit Terminal and reopen it. You should now be able to use Homebrew.
- Next steps: - Add Homebrew to your PATH in /Users/$USER/.zprofile:
-
3Update the configuration file manually if needed. If you didn’t follow these steps when you initially installed Homebrew, you can still update the config file manually. Here’s how:
- First, you may need to create the correct config file by entering the command touch ~/.zprofile in Terminal.
- Enter the command open -e ~/.zprofile to open the file in TextEdit.
- Add the following line to the file: eval "$(<Homebrew prefix path>/bin/brew shellenv)" .
- Replace “<Homebrew prefix path>" with the appropriate location prefix for your system (e.g., “/opt/homebrew” on a Mac with Apple Silicon).
-
Quit and restart Terminal. Once you’ve updated the shell config file, you’ll need to restart your shell session. Either quit Terminal and restart, or use the command source ~/.zprofile to reset the shell environment.
- Once Terminal restarts, you should be able to run brew commands!
Expert Q&A
Video
Tips
- In rare cases, you’ll still get the Command Not Found error even if Homebrew is installed and the $PATH is set correctly. In these cases, you might need to uninstall and reinstall Homebrew. You can find instructions for uninstalling Homebrew here.Thanks