brew doctor says "Error: /usr/bin occurs before /usr/local/bin" how to fix? brew doctor says "Error: /usr/bin occurs before /usr/local/bin" how to fix? bash bash

brew doctor says "Error: /usr/bin occurs before /usr/local/bin" how to fix?


$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/sbinexport PATH=$homebrew:$PATH

export makes the variable available to any child processes of the shell.


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 PATHPATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin


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