15

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?

0
13

"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".

3
  • yes, I already did it.
    – cindywmiao
    Oct 9 '14 at 16:34
  • did you also rebooted your mac? this is mandatory after changes in bash/bashrc/bash_profile
    – AlessioX
    Feb 8 '16 at 18:40
  • 2
    @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 '16 at 18:51
8

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

1
  • 3
    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 at 15:52
8

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:

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
  • That is not the usual path for brew and what actually failed. This answer can be salvaged if some details are sorted out.
    – mmmmmm
    Feb 9 at 17:53
0

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

https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/FAQ.md

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.

0

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 '19 at 12:31
-1

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

PROXY - 10.10.10.10

PORT - 8080

-1

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).

Half-Broken:

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.

Solution:

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:

/usr/local/sbin

Add this to:

/etc/paths

And things will work as expected.

-1

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)"' >> /Users/<yourusername>/.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.

2
  • 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 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 at 10:51
-1

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.

3
  • 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 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 at 13:29
  • Agreed that it works but the reason is wrong - to check on that how are you starting bash
    – mmmmmm
    Sep 16 at 13:51

You must log in to answer this question.

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