Fix “brew command not found” on Mac with zsh

Apr 19, 2023 - 13 Comments

Homebrew for Mac

If you’re a Homebrew user who is now experiencing a “zsh: command not found: brew” error message in zsh shell, you’re probably perplexed as to why the brew command line line tool is no longer working.

The reason you may be experiencing the command not found error for brew is because the zsh shell is not able to find the brew binary to execute for whatever reason, either because something is awry with your $PATH, or the Homebrew installation, or both. Thus, to fix the brew command not found error, we will perform a series of actions to reinstall Homebrew and then set the path manually if things continue to fail.

Fix “zsh: brew: command not found” on Mac with zsh Shell

First, we’re going to reinstall Homebrew. Do this even if you have already installed Homebrew into Ventura or your current MacOS version, and whether your Mac is an M1/M2 or otherwise.

At the command line, enter the following exactly:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Hit enter and proceed with the Homebrew installation as usual.

When installation has complete, attempt to use the ‘brew’ command again, for example to install a brew package, update, or remove a package.

If you continue to experience the brew command not found error message, you can resolve it by placing brew in your zshrc $PATH. You can check your PATH or add a new PATH with the export command with the

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc

Next, type the following to repair brew if needed:

brew doctor

The echo approach may be familiar to you if you have previously set environment variables.

Experiencing ‘command not found’ After Installing Oh-My-Zsh? Try This

Specific to many users who only experience the brew command not found problem after installing the popular Oh-my-zsh package, you may try manually adding the following line to your .zshrc file:

eval $(/opt/homebrew/bin/brew shellenv)

You can also add this to your zshrc with a single command:

echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zshrc

Again, try running brew doctor afterwards.

If you run the following brew command, you’ll also be given a solution of using the same string in the .zprofile:
brew help shellenv

brew help shellenv
Usage: brew shellenv

Print export statements. When run in a shell, this installation of Homebrew will
be added to your PATH, MANPATH, and INFOPATH.

The variables HOMEBREW_PREFIX, HOMEBREW_CELLAR and HOMEBREW_REPOSITORY are
also exported to avoid querying them multiple times. To help guarantee
idempotence, this command produces no output when Homebrew’s bin and sbin
directories are first and second respectively in your PATH. Consider adding
evaluation of this command’s output to your dotfiles (e.g. ~/.profile,
~/.bash_profile, or ~/.zprofile) with: eval “$(brew shellenv)”

With the Homebrew path set (or the shellenv approach to set necessary environmental variables), the brew command will work as expected again. If you’re curious where Homebrew packages are installed and kept in the file system

Did this trick work to resolve the “brew command not found” error message for you? Did you find another solution? Let us know your experiences in the comments.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Troubleshooting

13 Comments

» Comments RSS Feed

  1. Ibrahim Soro says:

    Thank you so much, it works for me 😂

  2. Sean C says:

    always add path variables at the end…there are very important reasons for that. so…

    echo “export PATH=$PATH:/opt/homebrew/bin” >> ~/.zshrc

  3. Leela says:

    This Helped me a Lot Thank you

  4. Raman says:

    It worked!!

  5. Bhavika says:

    Super helpful. Thanks.

  6. Ravi says:

    its worked for me for brew as well as pod.
    Thanks.

  7. mahninjaadenzel says:

    MAH NINJA!

    it worked

  8. raleck says:

    Hi all, I’m not a pro, but what worked for me was to install the newest home-brew via pkg. When installation is finished go to the terminal header bar -> Shell -> new window -> select Homebrew.

    then all brew commands work.

    cheers!

  9. Lani says:

    This worked for me, thank you! I’m on a mac.

  10. peter says:

    Went through all the suggestions with no success.
    I then did what Microsoft suggest with Windows and
    restarted my computer. SUCCESS!

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site