I installed brew before, but it does not work now.

When I run brew, it gives me the error -bash: brew: command not found

So I tried to reinstall using the code

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

But it gives me another one :

It appears Homebrew is already installed. If your intent is to reinstall you should do the following before running this installer again: rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

If I use the command rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup, it gives back the first error : -bash: brew: command not found

What should I do now?


13 Answers 13


I had the same problem—installed brew, used it, but now it doens't work, ie, brew command not recognized anymore.

The context of my brew-not-recognized-anymore problem is a bit more specific: I'm using iTerm instead of Terminal, I installed brew in the standard way to the standard place, I used brew to install zsh and oh-my-zsh, and at that point the brew command stopped working.

I wasn't able to find the solution to my subset of the brew-not-recognized-anymore problem anywhere, so I'm posting the solution in case anyone else has this sort of brew-not-recognized-anymore problem.

Adding this to my .zshrc solved the problem on a machine with Apple M1 CPU:

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

Note that this is not the same as adding to the PATH variable. The brew command is indeed located in those standard locations listed in other solutions. It turned out not to be a PATH variable thing that was causing this subset of the brew-not-recognized-anymore problem.

  • 1
    I don't know if it needs to be run every time I load my terminal, but this is the command brew had me run after installation (right after one other command) and that fixed my issue. Dec 6, 2021 at 3:30
  • 5
    I am using Apple Mac M1 Pro CPU. This worked for me. Thanks
    – TommyDo
    Jan 17 at 19:41
  • 1
    I had exactly the same issue as Matt, brew was not recognized anymore after installing oh-my-zsh. The above solution works, but I have to run that command every time I open the terminal. Is there a way to make it permanent?
    – cholo14
    Feb 7 at 9:45
  • 3
    @cholo14 open -a textedit ~/.zshrc and add the command on it's own line at the top of the file and save the file. if the file doesn't exist, create it by running touch ~/.zshrc
    – Matt S
    Feb 11 at 2:33
  • 1
    Can confirm that > eval "$(homebrew/bin/brew shellenv)" is enough to get my brew back up and running. Thanks for pointing me in the right direction!
    – user454322
    Mar 26 at 0:01
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

This code works for me on a MacBook Pro M1.


"Command not found" indicates that the brew binary isn't on one of the directories listed in your PATH environment variable. To check what your path is currently, run echo $PATH. By default, brew installs to /usr/local/bin. To set the path permanently, you should edit your ~/.bashrc file to contain the line export PATH="/usr/local/bin:$PATH".

On Aplle Silicon machines brew by default install path is /opt/homebrew/bin

  • yes, I already did it.
    – cindywmiao
    Oct 9, 2014 at 16:34
  • 1
    did you also rebooted your mac? this is mandatory after changes in bash/bashrc/bash_profile
    – AlessioX
    Feb 8, 2016 at 18:40
  • 3
    @Alessiox no it is not necessary to reboot the mac - only need to start a new Terminal and run from there (or even on most cases resource ~/.bash_profile
    – mmmmmm
    Feb 8, 2016 at 18:51

the -bash: brew: command not found error means that it didn't find the brew environment variable on your Mac.

The correct environment configuration in .bash_profile file should be like this:

export PATH="/usr/local/bin:$PATH"

So if you haven't config the brew environment variable, the correct step to config the brew environment variable on your Mac is:

  1. add the environment variable to your mac, the correct command is:

    echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
  2. Now we need to activate the changes. Type this command to activate and try drew doctor again:

    source .bash_profile

    Or if you had config the environment, you can use this command to open the file to check if the environment configuration is correct:

    /usr/bin/open ~/.bash_profile

    and then fix it to the correct text and then save and quit.

  3. Don't forget to activate your changes also. Still this command:

    source .bash_profile

  • 7
    Depending on where brew was installed you might have to replace export PATH="/usr/local/bin:$PATH" with export PATH=$PATH:/opt/homebrew/bin. All other steps are equal.
    – Jakob
    May 24, 2021 at 15:52

If your shell is zsh and your Mac is M1-based, enter these two commands after installing brew:

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

The first command adds:

  • an expanded PATH variable that includes the directories where brew and commands installed with brew are located
  • several shell variables used by brew

to the .zprofile initialization file.

The second command adds those same variables to the current shell, so that you can start using brew without re-reading .zprofile.

PS: For Intel Macs, use /usr/local instead of /opt/homebrew.

PPS: If you are running bash, use .bashrc instead of .zprofile.

  • For most homebrew installs and definitely when this question was written Homebrew install in /usr/local as one of its main selling points so that you don't need to edit the PATH in any shell files. Only in the last few months has it been forced to use a more standard Unix path and you have to edit the PATH
    – mmmmmm
    Jul 21, 2021 at 22:06
  • 1
    Also this assumes both an M1 Mac (Homebrew installs to /opt/homebrew on M1 only) and use of zsh (which is the modern default but doesn't automatically apply to accounts created before the switch). Can you edit the answer to make it more generic, and also explain what the commands actually do and how they solve the problem described in the question?
    – nohillside
    Jul 22, 2021 at 10:51

The FAQ has a section on this and a specific uninstall script, start there to get a clean system and then install again.


To uninstall Homebrew, paste the command below in a terminal prompt.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Download the uninstall script and run ./uninstall --help to view more uninstall options.


Might be that you just never downloaded.. I made that mistake. Thought I'd downloaded right, but found out I hit something other then return when it says to "press return to continue or any other key to cancel"

  • 1
    No because the OP says he gets the error "It appears Homebrew is already installed. "
    – mmmmmm
    Feb 6, 2019 at 12:31

If your shell is zsh and your Mac is M1-based

edit .zshrc

nano .zshrc


export PATH=/opt/homebrew/bin:$PATH

Quit terminal and re-open

try with


I chased my tail with the "command not found" error. I thought upgrading to Catalina might have borked my Homebrew installation (upgrading OSX requires you to upgrade MacPorts).


I checked my path and /usr/local/bin was there and an ls -al of that directory listed the installed Homebrew packages. So why was Homebrew still not happy?!?!? I tried another Homebrew command and that command SUCCEEDED. So Homebrew was half-broken: some things work, some things don't. Drat.


The command puking the error command not found was mtr which requires sudo access. Although the Homebrew documentation and every other answer I found on this error tells you to add /usr/local/binto your path, executables requiring sudo access live in the path:


Add this to:


And things will work as expected.

sudo ln -s /opt/homebrew/bin/brew /usr/local/bin/brew

This line bind homebrew from /opt with /usr/local, so you can use brew command everywhere. This is the only thing that helped me.


  • 1
    What does this do, how does it solve the problem described in the question?
    – nohillside
    Mar 19 at 16:25
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 19 at 16:28
  • 1
    Woudn't it be easier to add /opt/homebrew/bin to PATH then, with the additional benefit that any command installed via Homebrew will also work?
    – nohillside
    Mar 20 at 17:48
  • @nohillside I don't know, bro. Nothing else worked but this, so I shared the solution. Do you understand?:))
    – carrymiss
    Mar 21 at 14:04

Following command doesn't work if your are under proxy.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Instead use following -

ruby -e "$(curl -x http://DOMAIN%5cUSER_NAME:PASSWORD@PROXY:PORT -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Note we have to use %5c instead of "\" Similarly if your password has any special character replace it with unicode e.g for @ use %40 Refer this Unicodes

Replace above command with your own params

DOMAIN - Your Domain

USER_NAME - Your User Name

PASSWORD - password


PORT - 8080


This is what I did on Ubuntu 20:

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'>> ~/.bashrc

in contrast with what brew documentation suggests:

==> Next steps: Run these two commands in your terminal to add Homebrew to your PATH:

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/user/.profile

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

It seems .profile does not get read when .bashrc is there.

  • Incorrect. .profile is not read if .bash_profile exists .bashrc is read by all interactive bash sessions see bash documentation gnu.org/software/bash/manual/bash.html#Bash-Startup-Files
    – mmmmmm
    Sep 16, 2021 at 12:57
  • @mmmmmm This is also mentioned in ".profile" but ".bash_profile" is not there and yet thet first does not get read. The point is that this solution works.
    – DimiDak
    Sep 16, 2021 at 13:29
  • Agreed that it works but the reason is wrong - to check on that how are you starting bash
    – mmmmmm
    Sep 16, 2021 at 13:51

the easy answer here is: you need to read the output of the installation.

after your run the brew command it will guide you what to do next.

In my case it did tell me to run the following 2 commands to make brew available at the PATH

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/moelwekil/.zprofile    
eval "$(/opt/homebrew/bin/brew shellenv)"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .