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. Commented Dec 6, 2021 at 3:30
  • 15
    I am using Apple Mac M1 Pro CPU. This worked for me. Thanks
    – TommyDo
    Commented Jan 17, 2022 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
    Commented Feb 7, 2022 at 9:45
  • 7
    @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
    Commented Feb 11, 2022 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
    Commented Mar 26, 2022 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.

PS: If you are using bash on M1, run

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

instead of the first line above.

  • can confirm that this is the right way - I type in brew help shellenv and it says Consider adding evaluation of this command's output to your dotfiles (e.g. ~/.profile, ~/.bash_profile, or ~/.zprofile) with: eval "$(brew shellenv)"
    – CatFly
    Commented Sep 2, 2022 at 9:51
  • 1
    The applications I installed were working only in the terminal window I was installing. When I closed the window I had to re-install it. I added these commands to the text opened with the "nano ~/.bash_profile" command and closed it. After this process, everything worked as it should.
    – Mete
    Commented Dec 28, 2022 at 9:06
  • to make it work on M1 with bash, more or less same but: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
    – os11k
    Commented Apr 28, 2023 at 8:33
  • can confirm on my M2 as well. thank you so much. Commented Jun 4, 2023 at 16:55
  • 2
    no such file or directory: /opt/homebrew/bin/brew
    – Bersan
    Commented Jan 4 at 23:21

"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
    Commented Oct 9, 2014 at 16:34
  • 1
    did you also rebooted your mac? this is mandatory after changes in bash/bashrc/bash_profile
    – AlessioX
    Commented Feb 8, 2016 at 18:40
  • 4
    @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
    Commented Feb 8, 2016 at 18:51

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.

  • 1
    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
    Commented 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
    Commented Jul 22, 2021 at 10:51
  • It Works! macOS: Big Sur (version 11.4) Chip: Apple M1 Commented Mar 15, 2023 at 10:50

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

  • 8
    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
    Commented May 24, 2021 at 15:52

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

  • If your Mac is M1 based, you could edit the PATH variable with ~/.bash_profile add export PATH=$PATH:/opt/homebrew/bin and save. Exit the terminal. Now run brew command Commented Sep 2, 2022 at 13:30
  • tnx, work for me! Commented Dec 9, 2022 at 14:34

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
    Commented Feb 6, 2019 at 12:31

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
    Commented 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
    Commented 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
    Commented Sep 16, 2021 at 13:51

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.


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)"
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
    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
    Commented Mar 20, 2022 at 17:48
  • @nohillside I don't know, bro. Nothing else worked but this, so I shared the solution. Do you understand?:))
    – carrymiss
    Commented Mar 21, 2022 at 14:04

Following command doesn't work if your are behind a proxy.

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

Instead use the 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 to Unicodes.

You can replace parameters in the above command with your own parameters:

  • DOMAIN - Your Domain
  • USER_NAME - Your User Name
  • PASSWORD - password
  • PROXY -
  • PORT - 8080

You must log in to answer this question.

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