Reputation: 15432
➜ ~ /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
Upvotes: 418
Views: 978409
Reputation: 2925
Edit .zshrc
file :
nano .zshrc
The following should be enough :
export PATH="/opt/homebrew/bin:$PATH"
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 and M3 / M3 PRO and M4 / M4 PRO
Macbook Air M2 and M3
Update 2025
Upvotes: 151
Reputation: 4665
Improved Answer from @Spindizzy with example in terminal:
cd ~ | ls -a
touch .zshrc // if file .zshrc doesn't exists we create it
vim .zshrc
Paste export PATH=/opt/homebrew/bin:$PATH
there, save file and restart terminal.
Vim helper:
export PATH=/opt/homebrew/bin:$PATH
Upvotes: 13
Reputation: 9344
zsh: command not found: brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> 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)
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
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
.
Upvotes: 595
Reputation: 69
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:
In the Finder, open/edit the .zshrc
file or create one if you cannot find it.
Paste this code:
export PATH=/usr/local/homebrew/bin:$PATH
It should work.
Upvotes: 3
Reputation: 172
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)"
Upvotes: 2
Reputation: 144
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:
Edit .zshrc
file. Type:
nano ~/.zshrc
Add line in the editor:
export PATH=/usr/local/homebrew/bin:$PATH
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.
Upvotes: 1
Reputation: 109
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
Upvotes: 3
Reputation: 1138
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.
Upvotes: 1
Reputation: 1184
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.
Upvotes: 1
Reputation: 654
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)"`
Upvotes: 4
Reputation: 29
Solution for Ubuntu 20.04
After installing brew with:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
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)"
BEFORE closing that terminal copy
the output of:
echo $PATH
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
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.
Open .zshrc
file (mine is on home
hidden file)
At the beginning of the .zshrc
file add what we build on 5.
:
export PATH=/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH
Save and restart terminals
Check that is working with:
brew doctor
You should be set and brew should be started always with new terminals by default.
Upvotes: 1
Reputation: 760
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
Upvotes: 0
Reputation: 159
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)"
Upvotes: 0
Reputation: 936
In my case, I added the following line to ~/.zshrc
eval "$(/opt/homebrew/bin/brew shellenv)"
Upvotes: 7
Reputation: 1203
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)"
Upvotes: 29
Reputation: 1809
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
Upvotes: 6
Reputation: 276
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
Upvotes: 1
Reputation: 137
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"
Upvotes: 3
Reputation:
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.
Upvotes: 1
Reputation: 1122
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)"
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"
In terminal type source ~/.zshrc
and your done.
Upvotes: 5
Reputation: 180
Just add export PATH=/opt/homebrew/bin:$PATH
in your home directory
Restart if needed or just reopen your terminal
Upvotes: 17
Reputation: 2180
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.
Upvotes: 6
Reputation: 771
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.
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.
Upvotes: 77
Reputation: 64
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
Upvotes: 3
Reputation: 2498
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.
Upvotes: 6
Reputation: 159
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
Upvotes: 1
Reputation: 8924
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.
Upvotes: 727
Reputation: 37
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)"
Upvotes: 1
Reputation: 2256
make sure install brew first
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Upvotes: 9