When I print out the path in bash, it prints this:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
When I run System.out.println(System.getenv("PATH")); in Java running under Eclipse, it prints
/usr/bin:/bin:/usr/sbin:/sbin
How can I figure out why there is this discrepancy? I need to add /usr/local/bin to the PATH and make it available to Java apps under Eclipse. (note: I have made no modifications system paths, so these are the defaults set by the OS or perhaps by one or more of the applications i've installed.)
12 Answers 12
For those of you looking for an answer years later (Neon, Oxygen):
Some of my node and angular/angular2 tooling in eclipse failed due to missing $PATH entries in the MacOS terminal. Your tooling propably utilizes the embedded eclipse terminal which does not start providing your login/user shell. So you need to set the eclipse terminal in your eclipse preferences to start as --login shell in order to comprise your users PATH settings:
Go to:
Preferences -> Terminal -> Local Terminal
and set
Arguments to: --login
open a new Terminal inside Eclipse and your user's $PATH should be used from now on. Also everything you have set up in ~/.bash_profile will run when opening a new Terminal in Eclipse.
- 
 Best solution, solves the problem just by changing eclipse configuration in GUI.pXel– pXel2017年09月12日 12:22:20 +00:00Commented Sep 12, 2017 at 12:22
- 
 This answer made me upgrade to Oxygen, and that was all I needed to make it work.John– John2018年04月12日 13:30:31 +00:00Commented Apr 12, 2018 at 13:30
- 
 I do not have the "Terminal" submenu in Eclipse with version string "2019-06 (4.12.0)".tsj– tsj2019年09月06日 13:14:43 +00:00Commented Sep 6, 2019 at 13:14
- 
 @tsj You need to install "TM Terminal" plugin from Eclipse marketplace.Ibrahim.H– Ibrahim.H2021年02月04日 08:47:02 +00:00Commented Feb 4, 2021 at 8:47
Had the same problem. Here is my solution:
- Edit the - /etc/pathsfile to include the desired additional path.
- For a OSX installation, run - /Applications/eclipse/eclipsenot- /Applications/eclipse/Eclipse.app
- 
 1omg number 2 on here was the solution to SO MUCH FRUSTRATION. Thanks!!Tommy– Tommy2013年10月02日 16:39:10 +00:00Commented Oct 2, 2013 at 16:39
- 
 1I registered to this website just so I could upvote this answer - item #2 fixed it!Iftah– Iftah2016年07月06日 08:28:22 +00:00Commented Jul 6, 2016 at 8:28
- 
 Where can I find the etc/paths?John– John2018年04月12日 12:37:39 +00:00Commented Apr 12, 2018 at 12:37
- 
 1@John/etc/pathsis the full path of the file. You can do Cmd+Shift+G and then put "/etc" into it and press enter/return. You must find the file there named "paths".Sufian– Sufian2018年05月30日 10:56:02 +00:00Commented May 30, 2018 at 10:56
If you want to set an variable system wide on OSX you need to put it in your ~/.MacOSX/environment.plist file.
See this page on the apple website for more detail.
- 
 1Unfortunately, this doesn't seem to work for me.thSoft– thSoft2012年11月19日 22:44:08 +00:00Commented Nov 19, 2012 at 22:44
- 
 1Sadly, the above link is dead and Apple has undoubtably changed this behavior.Nik Reiman– Nik Reiman2024年04月12日 14:32:21 +00:00Commented Apr 12, 2024 at 14:32
Aha, I found this webpage which says
Note: Mac OS X does not include /usr/local/bin in its default PATH. Therefore, assuming you're using the default bash shell, please type (or include in /etc/profile) export PATH=/usr/local/bin:$PATH before using any of these tools.
Is this an appropriate/inappropriate thing to do? I get leery of editing system files unless I really know what I'm doing. /usr/local/bin is only writeable by root so I wouldn't be opening a security hole, would I?
Odd, I added the export path, and it has no effect on eclipse run from the Dock. Also I found this page about paths and my /etc/paths file has
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
and yet those paths don't show up in eclipse... is there an easy way to create/find a binary file that prints out $PATH, that I could run from the Dock, so I could debug this more easily? I don't know if Eclipse mucks around with the path.
- 
 3+1 for your final question. I'm wondering how to diagnose path issues in OS X not in bash or the Terminal.fideli– fideli2010年01月21日 00:19:51 +00:00Commented Jan 21, 2010 at 0:19
- 
 Note for future Googlers: Apple now includes/usr/local/binfirst in users'$PATH. (See here.)Telemachus– Telemachus2018年12月01日 15:47:25 +00:00Commented Dec 1, 2018 at 15:47
If you are on Eclipse (tested with "Mars"), you could change your "Run Configuration":
- Click on "Run" → "Run Configurations..."
- Choose the appropriate run configuration on the left
- Now choose tab "Environment"
- Click on "New..."
- In the "Name" field, enter "PATH"
- Now go to your Terminal, enter "echo $PATH" and copy the result
- Past the result into the "Value" field
- Klick "OK"
- Back in the "Environment" tab, make sure you select "Append environment to native environment"
Now Eclipse uses the same values for the PATH environment variable as your system does. Remember: This is only true for the run configuration you chose.
As already noted in your question, check in Java with:
System.getenv();
This tip above works for me: 1) add path to /etc/paths as root 2) start eclipse with $ECL_HOME/Eclipse.app/Contents/MacOS/eclipse instead of $ECL_HOME/Eclipse.app
- 
 This one works for me, thank you very much! In my case, the path to run Eclipse is /Applications/Eclipse.app/Contents/MacOS/eclipseTsung-Ting Kuo– Tsung-Ting Kuo2017年02月09日 23:24:05 +00:00Commented Feb 9, 2017 at 23:24
Most likely, one of your bash login scripts (.bashrc or .bash_profile) is changing $PATH. If you start Eclipse from the terminal, does it get /usr/local/bin in its path?
- 
 1good call! If I run Eclipse from the terminal, it has /usr/local/bin in the path. Now what should I do? Isn't /usr/local/bin something that should be in the path to all applications? which script can I put this in, so that if I run Eclipse from Finder or from the Dock, it will be in the path?Jason S– Jason S2009年08月23日 19:32:39 +00:00Commented Aug 23, 2009 at 19:32
- 
 1Also I don't have a .bashrc or .bash_profile in my user directory.Jason S– Jason S2009年08月23日 19:33:26 +00:00Commented Aug 23, 2009 at 19:33
Alternatively you might just add a symbolic link to your /usr/local directory pointing to your application. 
E.g. do as root:
ln -s /Applications/PhantomJS/phantomjs-1.9.2-macosx/bin/phantomjs /usr/local/phantomjs
This helped me to run (mvn test) the external PhantomJS application from within a Maven project in Eclipse.
- 
 This does not seem to have anything to do with$PATHor directories in$PATHlike/usr/local/bin. Could you please explain in more details?pabouk - Ukraine stay strong– pabouk - Ukraine stay strong2013年10月18日 10:00:46 +00:00Commented Oct 18, 2013 at 10:00
- 
 you put a symbolic link somewhere in the path, that points to the actual location which is not in the path. I've done it before, it works for single executables, doesn't work for a directory full of filesJason S– Jason S2013年10月18日 19:37:55 +00:00Commented Oct 18, 2013 at 19:37
You can modify the global osx path by adding a line to /etc/launchd.conf and rebooting your computer. 
setenv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Works in OSX 10.8 and 10.9
https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x/277034#277034
Eclipse NEON, mac OS X 10.11.6
The terminal in Eclipse can not use mvn command.(I make one soft link of mvn in /usr/local/bin)
Temp solution:
Right click /Applications/eclipse -> show package contents -> contents -> MacOS -> double click eclipse to start.
Start Eclipse this way , Eclipse can detect all the path settings and then I can use mvn command in Eclipse terminal now.
You can right click eclipse in this folder and make alias to start it conveniently.
I don't know why right now. I think this should be one eclipse BUG.
edit the ~/.bash_profile to include the path
instead of starting in the launchpad,
open the terminal and starting it as
/Applications/Eclipse.app/Contents/MacOS/eclipse
That did the trick for me.
Pulling together a few answers and updating to something easy:
- Right-click Eclipse.app and choose "Show Package Contents"
- Navigate to Contents/MacOS to find "eclipse".
- Right-click and choose "Make Alias", or drag and drop it while holding command and option.
- Put the alias somewhere convenient, like back in Applications.
- Double-click to launch.
- There is no Step 6!
Not only will this open a handy Terminal window showing the raw Eclipse output, it will automatically adopt whatever path you have set in your login shell.
So you can use any of the normal methods to set your path (editing /etc/paths or ~/.bash_profile or just installing well behaved command line tool like mbed), and worry no further. If you can call it from the Terminal then Eclipse can call it too.