After installing Homebrew I get `zsh: command not found: brew`

MacosTerminalHomebrew

Macos Problem Overview


➜  ~ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-e:77: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040677
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
The current contents of /usr/local are bin CODEOFCONDUCT.md etc git lib Library LICENSE.txt munki README.md sbin share .git .github .gitignore
➜  ~ brew install maven
zsh: command not found: brew

Macos Solutions


Solution 1 - Macos

I had a similar issue on macOS Big Sur (11.0.1). In my case homebrew was saved in /opt/homebrew/, and not in /usr/local/....

So I added

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

to .zshrc file in my home directory, and the ZSH shell was able to find the brew command.

Solution 2 - Macos

for this error zsh: command not found: brew

  1. Make sure you've installed Brew, with this (wait until its done installing) (Edit: added ending quote to the end)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Then follow NEXT STEPS shown on command line, it should show something like this
==> Next steps:
- Add Homebrew to your PATH in /Users/$USER/.zprofile:
    echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
    eval $(/opt/homebrew/bin/brew shellenv)
  1. Copy and paste the first line on the same terminal window, then hit enter
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
  1. Then Copy and paste the last line on the same terminal window, then hit enter
eval $(/opt/homebrew/bin/brew shellenv)

Finally you should be able to use brew help and if that works, it means that brew was installed properly and running from ZSH.

Solution 3 - Macos

Homebrew has been installed on you computer. You need to modify your PATH like this:

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

or execute brew from its origin:

/usr/local/bin/brew install maven

Solution 4 - Macos

Here are the steps I did...

1.Install homebrew

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

2.Run brew help and see if it's working... If it showing an error "zsh: command not found: brew" follow along.

  1. Change the path to:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/"YOUR USER NAME"/.zprofile

Remember to change the "USER NAME" with yours, Then type in:

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

Once successfully running these command type "brew help" to see if everything went ok.

Solution 5 - Macos

I got the same issue after installing Homebrew in my MacBook (macOS Big Sur V 11.0.1).

After installation, in the console it says what should be done:

> ==> Next steps: > - Add Homebrew to your PATH in /Users/USER/.zprofile: > echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/USER/.zprofile > eval $(/opt/homebrew/bin/brew shellenv) > - Run brew help to get started

Executing those two commands, in order, will add the brew command into the PATH:

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

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

Solution 6 - Macos

Just add export PATH=/opt/homebrew/bin:$PATH in your home directory

Restart if needed or just reopen your terminal

Solution 7 - Macos

make sure install brew first

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

Solution 8 - Macos

I will just demonstrate the answer from @Spindizzy terminally speaking:

cd ~ | ls -a
touch .zshrc // if file .zshrc doesn't exists we create it
vim .zshrc

Paste PATH=/opt/homebrew/bin:$PATH there, save file and restart terminal.

Vim helper:

1. press "i" to interactive mode in vim, paste:
export PATH=/opt/homebrew/bin:$PATH
2. press "esc" type ":wq" and hit enter

Solution 9 - Macos

Update 2022

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

Solution 10 - Macos

edit .zshrc

nano .zshrc

add

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

Solution 11 - Macos

In fish shell on Apple M1, I had to add /opt/homebrew/bin to the fish_user_paths global env. I had to do this manually because set -U fish_user_paths /opt/homebrew/bin $fish_user_paths got > set: Universal variable 'fish_user_paths' is shadowed by the global variable of the same name.

Solution 12 - Macos

Basically your homebrew is saved in /opt/homebrew/, and not in /usr/local/.... path

Open .bash_profile in your home directory and add :

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

and restart the terminal. You will have it up and running.

Solution 13 - Macos

This morning i too faced the same issue. The problem is path for homebrew is not set correctly.

Follow below steps

1.install homebrew correctly. In the terminal type below cmd.

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

  1. set the path in your .zshrc file in terminal type

    open ~/.zshrc

    In .zshrc file add the path like below

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

  2. In terminal type source ~/.zshrc

    and your done.

Solution 14 - Macos

may be you have followed this step from homebrew homepage.

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

so may your system not able to allocate path so follow below steps.

sudo nano /etc/paths

paste

/opt/homebrew/bin:$PATH

save and close

Solution 15 - Macos

In my case, I added the following line to ~/.zshrc

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

Solution 16 - Macos

Go to the official Homebrew site.

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

Next steps:

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Try: brew install hello

Solution 17 - Macos

When installing, brew has this -NEXT STEPS console log when is needed to include its path to bash.

run the followed steps:

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

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

Solution 18 - Macos

If you're on WSL2 make sure to follow the final linux installation instructions for linuxbrew.

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Solution 19 - Macos

I had the same issue with Ubuntu and Arch Linux. I solved this problem by adding the path of the bin folder of brew to the .zshrc file.

The path to my brew installation bin directory is /home/linuxbrew/.linuxbrew/bin

Add following line to the ~/.zshrc file
export PATH=/home/linuxbrew/.linuxbrew/bin:$PATH

After this do open a new terminal and the brew command will not be available.

Solution 20 - Macos

I just did echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc as I'm using oh-my-zsh. After doing this should be able to use brew.

Solution 21 - Macos

Since you're using zsh, you need to add the PATH to your .zshrc file:

vim ~/.zshrc

Add:

export BREW_HOME="/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:$BREW_HOME"

Solution 22 - Macos

To your .zshrc file, add the path to your homebrew/bin, wherever that might be. In my case, homebrew was installed in my home directory. Add:

export PATH="/<path-to-homebrew-directory>/bin:$PATH"

Restart your terminal for it to pick up the changes to your .zshrc

Solution 23 - Macos

I tried the above method export PATH=/opt/homebrew/bin:$PATH But it didnt work.

So i did my research and realized that the above code works for Apple chip Mac and not for intel chip Mac.

So i made an edit to the code since my Mac is intel based and i did this which worked perfectly:

  1. In your finder, open/edit the .zshrc file or create one if you cannot find it.

  2. paste this code:

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

It will work!!!

Solution 24 - Macos

might be late, but surely helpful. you have to install brew on first thing. just run the below command to do that:

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

Solution 25 - Macos

Run the following setup then you will be ready to use brew

Run unintsall script :-

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

Set Git Compression :- git config --global core.compression 0

Set Git buffer size :- git config --global http.postBuffer 1048576000

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

Solution 26 - Macos

You should add both /opt/homebrew/bin and /opt/homebrew/sbin to $PATH env.

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

for quick, run command

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

then run brew doctor to checking

Solution 27 - Macos

Solution for Ubuntu 20.04

  1. After installing brew with:

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

  2. and ran what it says after (this did nothing for me just added lines to .zprofile every time i ran it):

    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/blcuser/.zprofile

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

  3. BEFORE closing that terminal copy the output of:

    echo $PATH

  4. Should be similar to this:

/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

What we need is the path to brew which is this part of the previews path (for you might be a different path)

/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin

  1. Open NEW terminal and try to build the whole first path with:

Should be like: <brew_path>:$PATH

For me was this: echo /home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH

Should output the first whole path we output on 4.

  1. Open .zshrc file (mine is on home hidden file)

  2. At the beginning of the .zshrc file add what we build on 5.:

    export PATH=/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH

  3. Save and restart terminals

  4. Check that is working with:

    brew doctor

You should be set and brew should be started always with new terminals by default.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionElad Benda2View Question on Stackoverflow
Solution 1 - MacosSpindizzyView Answer on Stackoverflow
Solution 2 - MacosJonathan SanchezView Answer on Stackoverflow
Solution 3 - MacosHamid RouhaniView Answer on Stackoverflow
Solution 4 - MacosSavyo RelavioView Answer on Stackoverflow
Solution 5 - Macossamme4lifeView Answer on Stackoverflow
Solution 6 - MacosGyanaa-VaibhavView Answer on Stackoverflow
Solution 7 - MacosYao LiView Answer on Stackoverflow
Solution 8 - MacosSebastian VoráčView Answer on Stackoverflow
Solution 9 - MacosSrasView Answer on Stackoverflow
Solution 10 - MacosJatnielView Answer on Stackoverflow
Solution 11 - MacosmmellView Answer on Stackoverflow
Solution 12 - MacosAnubhavView Answer on Stackoverflow
Solution 13 - MacosAniketView Answer on Stackoverflow
Solution 14 - MacosAmit KumarView Answer on Stackoverflow
Solution 15 - MacosSomeCode.NETView Answer on Stackoverflow
Solution 16 - MacosMerci GkmView Answer on Stackoverflow
Solution 17 - MacosRafoView Answer on Stackoverflow
Solution 18 - MacosBen MurdochView Answer on Stackoverflow
Solution 19 - MacosAnkush ChavanView Answer on Stackoverflow
Solution 20 - MacosChuang JYView Answer on Stackoverflow
Solution 21 - MacosouterSpaceView Answer on Stackoverflow
Solution 22 - MacosssareenView Answer on Stackoverflow
Solution 23 - MacosNelvin NakoroView Answer on Stackoverflow
Solution 24 - MacosRaheem ShaikView Answer on Stackoverflow
Solution 25 - MacosAnkita AgarwalView Answer on Stackoverflow
Solution 26 - MacosPatrickzView Answer on Stackoverflow
Solution 27 - MacosSantiago DíazView Answer on Stackoverflow