brew doctor says "Error: /usr/bin occurs before /usr/local/bin" how to fix?
Solution 1
$PATH is just a variable containing a string. To put something in front:
% PATH=/usr/local/bin:$PATH
% echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
This is not dangerous, since it only applies to the current shell you have open (it will not affect the path for your system or other shells).
To change the path automatically for all shells you open, put it in ~/.profile
. You can create this file if it doesn't already exist.
In ~/.profile
:
homebrew=/usr/local/bin:/usr/local/sbin
export PATH=$homebrew:$PATH
export
makes the variable available to any child processes of the shell.
Solution 2
I found another way to solve this.
sudo vim /etc/paths
and add /usr/local/bin and /usr/local/sbin like this
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
open a new terminal tab, and then you will see
~ $ env|grep PATH
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Solution 3
Just run the following line in your favorite terminal application:
echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile
Restart your terminal and run
brew doctor
the issue should be resolved
Solution 4
I just created a .bashrc file and added
homebrew=/usr/local/bin:/usr/local/sbin
export PATH=$homebrew:$PATH
That seemed to have done the trick!
Solution 5
Maybe OP's using zsh.
The way to solve it is edit the ~/.zshrc everytime you open iterm will load this file.
Change the words about PATH.
AdamT
Updated on June 15, 2020Comments
-
AdamT almost 4 years
Adams-MacBook-Pro% brew doctor Error: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew. The following tools exist at both paths: clusterdb createdb createlang createuser dropdb droplang dropuser ecpg git git-cvsserver git-receive-pack git-shell git-upload-archive git-upload-pack gitk pg_config pg_dump pg_dumpall pg_restore pg_upgrade psql reindexdb vacuumdb Consider amending your PATH so that /usr/local/bin is ahead of /usr/bin in your PATH.
Here is my path:
Adams-MacBook-Pro% echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I thought it was dangerous to move things to the front? How do I solve this problem? Also, I'm not even sure where to find where /user/bin is declared in the path.
Thanks
-
AdamT almost 12 yearsi did this, created ~/.profile and then echo $PATH but the path didn't change. I closed the terminal and reopened but it was still the same path. brew doctor still complaining.
-
Dean almost 12 yearsTo get any changes to ~/.profile to take effect, you either have to reopen your terminal, or type
% source ~/.profile
. As to why it's not working, first make sure that the file is being run as expected. Add another line to~/.profile
echo 'profile works!'
then run% source ~/.profile
. Let me know if you see that printed to the screen. -
Dean almost 12 yearsI should also note that whitespace matters here. There can't be spaces on either side of the equals sign.
-
AdamT almost 12 yearsyes, printed to the screen "profile works!". also, user/local/bin is now in the front. brew doctor says: "Your system is raring to brew." However, I removed "echo 'profile works!' and now the path is broken again.
-
Dean almost 12 yearsDoes the same thing happen when you open a new terminal (both the message and your path being changed)?
-
AdamT almost 12 yearsif run "source ~/.profile" then it says "profile works" and brew doctor is happy. if i close the terminal and echo $path and brew doctor everything is unchanged (remains broken).
-
Dean almost 12 yearsBut does the message still get printed? .profile is an init script, but there are a few others and your path may be getting set in one of them as well. Check to see if
~/.bashrc
or~/.alias
exist. If the message is printed, but $PATH is unchanged, then $PATH may be getting set by a different script. If the message isn't being printed, then .profile isn't even being run. -
AdamT almost 12 years@Dean, .profile is being run. when i follow your directions it prints out the message. however, when i close the terminal and reopen and do "brew doctor" or just "echo $PATH" i can see the path hasn't been changed.
-
AdamT almost 12 years@DennisWilliamson, adding "homebrew=/usr/local/bin:/usr/local/sbin" and "export PATH=$homebrew:$PATH" to .bashrc doesn't work. path remains unchanged and brew doctor remains angry.
-
Dean almost 12 yearsHmmm, the only thing I can think of is that some other file is being run after .profile/.bashrc which is resetting your path (perhaps .bash_profile or .bash_login. Run
grep -l "PATH=" ~/.*
to see if there are any other files in your home directory setting the path. -
AdamT almost 12 yearshere is what I got:/Users/adam/.bash_profile,/Users/adam/.bashrc, /Users/adam/.viminfo, /Users/adam/.zsh_history, /Users/adam/.zshrc, The problem is the zshrc file which has this: export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin, when I moved /user/local/bin ahead of /user/bin then terminal didn't know what anything was (brew, mvim, etc.) What do I do now?
-
AdamT almost 12 yearsi think i got it. need to test for a bit to make sure.
-
Dean almost 12 yearsGood to hear. I assumed you were using a bash shell because it's the default, but it looks like you may be using a z shell instead (you can tell by running
echo $SHELL
). -
pbreitenbach about 11 yearsshould be /usr/local/bin (not sbin)?
-
Harry Palmer over 10 yearsThis solved it for me - I was using the zsh so just editing .profile or .bash_profile would not work, but adding those lines to .zshrc did the trick.
-
Walrus the Cat over 9 yearsIMO this is the cleanest way to solve it. It actually fixes the underlying problem, and doesn't put entries into the PATH twice.
-
R.D. over 9 yearsThis worked for me. I tried what brew suggested me, creating .profile, and even modifying the .bash manually. Of course, I did restart the computer to make sure it wasn't that the problem. Nothing worked except for this answer. Thanks!
-
consideRatio over 9 yearsThis is exactly what i wanted to find, i was looking to find where those entries were in the PATH variable where coming from to add like you did.
-
wizofwor almost 9 yearsIf you are using zsh like me you should change
~/.zshrc
instead of~/.profile
or~/.bash_profile
. -
DjebbZ almost 8 yearsAgree, this should be the accepted answer, since this worked perfectly for me.
-
tscizzle over 6 yearsSee Lelouchcr's answer about editing /etc/paths. For me,
/usr/local/bin
was already in thePATH
, just not before/usr/bin
./etc/paths
is where you can edit that order. (Normally I do adding toPATH
in my~/.bash_profile
, like how this answer uses~/.profile
, but/usr/local/bin
and/usr/bin
are special.)