After installing Homebrew I get `zsh: command not found: brew` [closed]
Asked Answered
P

31

362
➜  ~ /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
Panatella answered 15/4, 2016 at 21:44 Comment(0)
P
636

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.

Phonoscope answered 6/1, 2021 at 21:12 Comment(10)
export PATH=/opt/homebrew/bin:$PATH it helps, but how did you know that you have it there? and $PATH does this mean a new folder? I get this steps in terminal: Add Homebrew to your PATH in /Users/admin/.zprofile: echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/admin/.zprofile eval $(/opt/homebrew/bin/brew shellenv) Barling
The path was shown in the terminal after Homebrew was done with the installation on my machine. '$PATH' just means that this new path will be added to the variable called PATH, known by the zsh shell. However this syntax is standard for bash.Phonoscope
hi where could I find .zshrc or that so called home directory? thank youKlatt
Either open a complete new terminal, you should start in the home directory, or if you somewhere in another directory, you can find it by entering cd ~.Phonoscope
That was the exact problem for me. My homerbew was installed in /opt/homebrew and not in /usrl/localParterre
Quick tip, use source ~/.zshrc to make any changes to that file come into effect. Else, close and re-open your terminal.Mucor
If you are missing the file .zshrc in home ~ (e.g there is only zsh_sessions and zsh_history) simply create that file (touch .zshrc) and paste suggested export.Jesuit
Down in answers I demonstrated @Phonoscope answer step-by-step terminally speakingJesuit
what should add instead $PATHKellikellia
If you have installed homebrew recently, you may add export PATH=/opt/homebrew/bin/brew:$PATH to your .zshrc fileRimose
C
525

for this error zsh: command not found: brew

  1. Make sure you've installed Brew, with this (wait until it's 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 the 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.

Choroiditis answered 2/2, 2021 at 23:23 Comment(7)
This Works in Ubuntu 21.04 with linuxbrew, after thar, don't forget to signout or restart. thanks brother for this. for linux user. use this "eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" and add this to ~/.zprofileZaid
This is exactly what I had to do and what it told me to do, but I refrained from pasting those commands as they showed up only on my machine on running the install command from their official website for HomeBrew installation, while it didn't have a second step in the installation process on my friend's machine as new as mine (A day old). haha my bad. If anyone else went down the same route, I feel ya! And, this answer literally told me: "Do what you read in the console output of your terminal. Don't question. It at the least won't turn a time bomb on" Thanks @Jonathan SanchezBrumley
after running these commands it works fine, but when I close the the terminal and reopen it says -bash: brew: command not foundVaricolored
For me on a Mac, after running step 1, I'm able to use brew to install node brew install nodeRegiment
Still worked for me at May 2020.Stook
I'm kind of annoyed that you have to run the steps to install it into your PATH separately. Typically anytime you install something from a package manager, it automatically loads it into your PATH for you -- the homebrew maintainers deciding NOT to do that violates the principle of least surprise imho.Fullblooded
@Varicolored run the above steps again, this time adding it to your bash profile echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.bash_profileThumbstall
O
118

Edit .zshrc file :

nano .zshrc

The following should be enough :

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

And add this to the beginning of the file :

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

Save and run :

source ~/.zshrc 

Tested and working Apple M1 / M1 PRO and M2 / M2 PRO / M3 / M3 PRO

Macbook Air M2

Obeah answered 4/1, 2022 at 8:8 Comment(6)
After all, don't forget to run: source ~/.zshrcBarrier
Finally! The only answer that worked!Rouble
Do someboy have an Idea why this come on the first place ? I have to do that every time I'm opening vs codeJos
that's working for apple m2 macbook. thanks.Steno
working on m2 Mac mini, thanks!Cowpoke
Thanks it's working for me in Macbook Air M2.Articulator
E
94

Update 2024

export PATH="/opt/homebrew/bin:$PATH"
Ethics answered 19/4, 2022 at 3:23 Comment(2)
This worked for the me, the selected answer above did not.Four
specifically, homebrew is picking a different directory depending on if you're running an intel processor /usr/local or an apple processor /opt/homebrew: docs.brew.sh/InstallationAmorino
P
74

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.

Perrault answered 22/4, 2021 at 5:16 Comment(6)
this worked for MacOS Monterey for those lookingRea
This works for mac OSTedric
This worked for me in Monterey 12.2.1Davita
This worked for Mac OS 12.5Lindley
Worked for Ventura 13.1Ellyellyn
Would be easier to just do echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> ~/.zprofile. That way you don't need to get the username right.Beebe
R
64

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
Reclaim answered 23/4, 2016 at 0:41 Comment(2)
just to complement: to make that change to PATH a permanent one, you should insert that export ... command into your local ~/.zshrcTigerish
The .zshrc should already have this line in it and you would just need to remove the # to uncomment and restart your shell.Flagstone
A
28

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)"
Addicted answered 31/1, 2021 at 2:14 Comment(2)
Solved my problem.Gob
This worked on macos MontereyTubulate
K
16

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

Restart if needed or just reopen your terminal

Kacey answered 29/5, 2021 at 5:52 Comment(1)
I'm using macOS 14.0 M1 and running this command in a terminal solved the issue for me eval $(/opt/homebrew/bin/brew shellenv)Acetabulum
H
11

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
Hatchel answered 31/10, 2021 at 17:41 Comment(0)
G
9

make sure install brew first

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Gospodin answered 12/8, 2019 at 23:57 Comment(0)
T
7

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

eval "$(/opt/homebrew/bin/brew shellenv)"
Torrent answered 15/1, 2022 at 9:6 Comment(0)
C
6

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.

Chou answered 24/2, 2021 at 23:33 Comment(1)
As of fish 3.2.0, released in March 2021 fish_add_path /opt/homebrew/bin should be enoughUrn
P
6

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.

Pyrrolidine answered 20/5, 2021 at 18:29 Comment(0)
O
6

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

Ordinarily answered 6/12, 2021 at 20:20 Comment(0)
S
5

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.

Sequoia answered 27/8, 2021 at 10:1 Comment(0)
T
4

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)"`
Tsimshian answered 2/3, 2022 at 21:5 Comment(0)
E
3

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

Estis answered 2/3, 2021 at 11:59 Comment(0)
V
3

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"
Vagina answered 21/10, 2021 at 2:23 Comment(0)
F
3

I tried:

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

but it didn't work.

I researched the problem and realized that the above code works for only Apple chip Macs and not Intel chip Macs.

I edited the code, since my Mac is Intel-based, using:

  1. In the 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 should work.

Fracas answered 12/4, 2022 at 6:33 Comment(0)
S
3

For the latest version as of 6-oct-2022...

==> Next steps:

  • Run these three commands in your terminal to add Homebrew to your PATH:

    echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/tusharkhatri/.zprofile

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

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

  • Run brew help to get started

  • Further documentation: https://docs.brew.sh

Sarcomatosis answered 6/10, 2022 at 14:45 Comment(0)
A
2

It help me. Just run follow command:

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/gureenkov56/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/gureenkov56/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Anarch answered 8/1, 2023 at 14:0 Comment(0)
T
1

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)"
Traceetracer answered 17/6, 2020 at 12:17 Comment(0)
H
1

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
Hatbox answered 17/1, 2021 at 1:4 Comment(1)
For me, even following the installation instructions, it was not sufficient. Every time I restart my terminal, I got brew was not found. What I did is $ touch .bash_profile, then $ cp .profile .bash_profile and restart WSL2. That's how I solve my issues.Eyesore
C
1

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 be available.

Courante answered 20/8, 2021 at 6:13 Comment(0)
C
1

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.

Cloris answered 10/9, 2021 at 7:36 Comment(0)
P
1

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

Porterporterage answered 29/10, 2021 at 21:3 Comment(0)
S
1

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.

Strengthen answered 24/2, 2022 at 14:52 Comment(0)
L
1

Maybe it's not so obvious but in addition to the above steps, check your .zshprofile is not corrupted with any extraneous quotation marks. You should also close all terminal instances.

Libelant answered 2/10, 2022 at 9:54 Comment(0)
C
1

16.11.2022 - Update
During brew installation I got multiple lines informing me about where brew will be installed. For me terminal said:

This script will install:
...
/usr/local/Homebrew

So path I needed was the last one. Steps to fix the issue:

  1. Edit .zshrc file. Type:

    nano ~/.zshrc

  2. Add line in the editor:

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

  3. Hit Control+X to Exit the editor, Y to accept the changes and return to accept where file is going to be saved.

After all you need to refresh the terminal you use. You can either close the process of it and open or type:

source ~/.zshrc

That's it! Hope it helped.

Corvin answered 16/11, 2022 at 20:23 Comment(0)
I
0

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

Imparisyllabic answered 14/2, 2022 at 15:41 Comment(0)
D
0

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

Drastic answered 20/2, 2022 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.