38
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
  • 6,405
  • 10
  • 49
  • 75
  • 4
    Everyone who has this problem, please do as Homebrew says and run `echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile` AND DO NOT FORGET to restart Terminal (or whatever command line tool you're using) and try running `brew doctor` again. – Oliver Tappin Dec 28 '13 at 00:40
  • For those who already have `/usr/local/bin` in their PATH but just not before `/usr/bin`, see [Lelouchcr's answer](https://stackoverflow.com/a/24219682/3391108) about editing `/etc/paths` (to keep your PATH neater by not having duplicate entries). – tscizzle Aug 11 '17 at 15:21

9 Answers9

49

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

Community
  • 1
  • 1
Dean
  • 8,632
  • 6
  • 45
  • 61
  • i 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. – AdamT Jul 04 '12 at 22:31
  • 2
    To 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 Jul 04 '12 at 22:37
  • I should also note that whitespace matters here. There can't be spaces on either side of the equals sign. – Dean Jul 04 '12 at 22:41
  • yes, 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. – AdamT Jul 04 '12 at 22:45
  • Does the same thing happen when you open a new terminal (both the message and your path being changed)? – Dean Jul 04 '12 at 22:47
  • if 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). – AdamT Jul 04 '12 at 22:51
  • But 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. – Dean Jul 04 '12 at 22:55
  • @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 Jul 05 '12 at 00:47
  • @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. – AdamT Jul 05 '12 at 00:48
  • Hmmm, 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. – Dean Jul 05 '12 at 05:53
  • here 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 Jul 06 '12 at 05:10
  • i think i got it. need to test for a bit to make sure. – AdamT Jul 06 '12 at 05:27
  • Good 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`). – Dean Jul 06 '12 at 21:36
  • If you are using zsh like me you should change `~/.zshrc` instead of `~/.profile` or `~/.bash_profile`. – wizofwor May 10 '15 at 17:09
  • See [Lelouchcr's answer](https://stackoverflow.com/a/24219682/3391108) about editing /etc/paths. For me, `/usr/local/bin` was already in the `PATH`, just not before `/usr/bin`. `/etc/paths` is where you can edit that order. (Normally I do adding to `PATH` in my `~/.bash_profile`, like how this answer uses `~/.profile`, but `/usr/local/bin` and `/usr/bin` are special.) – tscizzle Aug 11 '17 at 15:19
23

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
Lelouchcr
  • 490
  • 4
  • 7
  • 3
    IMO this is the cleanest way to solve it. It actually fixes the underlying problem, and doesn't put entries into the PATH twice. – Walrus the Cat Sep 19 '14 at 00:02
  • This 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! – R.D. Oct 31 '14 at 22:26
  • This 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. – consideRatio Jan 18 '15 at 10:42
  • Agree, this should be the accepted answer, since this worked perfectly for me. – DjebbZ Jun 05 '16 at 21:36
10

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

iceturk22
  • 341
  • 3
  • 4
5

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!

pixel 67
  • 1,530
  • 18
  • 22
3

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.

Nagama Inamdar
  • 2,851
  • 22
  • 39
  • 48
Slahser
  • 31
  • 3
2

If you really want to make it permanent and default, edit the file /etc/paths (using sudo) and move /usr/local/bin to the top of the list.

In my own .bash_profile I use a script called "pathadd" that prevents my PATH from getting unwieldy and full of duplicates when shells are forked. So I took the /etc/paths action specifically to avoid having duplicate directories in the PATH by adding /usr/local/bin to the front again and again.

Mojo
  • 2,687
  • 5
  • 30
  • 42
1

You need to restart your Terminal after any change with $PATH.

0

On OS X Mountain Lion that needed edits was ~/.bash_profile

Slava V
  • 16,686
  • 14
  • 60
  • 63
0

I'm using linuxbrew with wsl and got a similar error warning.

### .zshrc ###
export PATH="$PATH:/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:/home/linuxbrew/.linuxbrew/sbin"

The problem was that $PATH was written at the beginning. The description has been changed as follows.

### .zshrc ###
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export PATH="/home/linuxbrew/.linuxbrew/sbin:$PATH"

After running source ~/.zshrc, I ran brew doctor and the error disappeared.