Mac Mac setup Tech

Really, really add /usr/local/bin to the PATH variable on Mac OS X

Since Mac OS X El Capitan you cannot put any custom files under /usr/local/, even when you sudo as much as you can (so even with administrator rights). Therefore, you are forced to use /usr/local/bin for your custom executables. If you are using Homebrew to install certain executables on your system, the programmes will be installed under the path /usr/local/bin as well. However, the path /usr/local/ is not included in the system’s default PATH variable so you cannot e.g. use these executables from within your Java programmes.

You most-probably want to add the path /usr/local/bin to the PATH environment variable to add the executables to your default executables. E.g. you can do so by editing the file ~/.profile and add the expression

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

But does this really add the executables under the path /usr/local/bin to the default executables? No, it does not. E.g. when you are running Java applications that make execute some system executables/programmes using


Imagine calling an executable myex under /usr/local/bin. Then


would result in an error because the default path configuration does not include /usr/local/bin, its shape is usually like /usr/bin:/bin:/usr/sbin:/sbin. A workaround may be to change the Java code and explicitly source the .profilefile

Runtime.getRuntime().exec("source ~/.profile; myex")

or to call the executable using an absolute path /usr/local/bin/myex


But both would make strong assumptions either about the shape of the profile or about the location of the executable. So, the better solution is to add the myex to the default executable path. This comment on github provides an answer: Open a Terminal window and copy & paste the command

sudo launchctl config user path /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

This will set the default environment and add definitely make the executables under /usr/local/bincallable for and from other programmes.

Leave a Reply