How to fix “Brew command not found” on Mac

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.

  1. Open Terminal.
  2. Type or paste the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Press Return. You will see information in the Terminal window explaining what will be installed and where it will be installed.
  4. Press Return again.
  5. Type in your admin password and press Return.
  6. Wait for a message telling you the installation has finished.
  7. 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

Tip: Uninstall any app on your Mac easily

The process for reinstalling Homebrew is pretty simple, as you can see above. However, if you need to uninstall and reinstall an application in your Applications folder, it’s more complicated. You can’t just drag the application to the Trash and empty it — that will leave behind lots of files associated with the app. These also need to be removed to free up space and prevent problems in the future. The easiest way to do that is to use a specialist uninstaller. We recommend CleanMyMac X. It allows you to uninstall any app easily. You can uninstall multiple apps at the same time as well as remove leftover files from apps that weren’t properly uninstalled previously and even reset misbehaving apps. You can download CleanMyMac X for free here.

All apps selected in the Uninstaller module of CMMX

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

Tip: How to maintain your Mac regularly

It’s a good idea to run regular maintenance on your Mac to prevent problems with it. That means running macOS maintenance scripts, freeing up RAM, clearing DNS cache, and reindexing Spotlight. Doing all that manually is time-consuming and difficult, but CleanMyMac X’s Maintenance module can do it for you, as well as repairing disk permissions, thinning out Time Machine snapshots, clearing purgeable disk space, and speeding up Mail. It takes only a few clicks and may save you a lot of trouble in the long run.

Free up Mac RAM with CleanMyMacX

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.

Laptop with CleanMyMac
CleanMyMac X

Your Mac. As good as new.