21

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

Chealion
26.4k8 gold badges69 silver badges76 bronze badges
asked Aug 23, 2009 at 19:21

12 Answers 12

15

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.

answered Jul 19, 2017 at 11:19
4
  • Best solution, solves the problem just by changing eclipse configuration in GUI. Commented Sep 12, 2017 at 12:22
  • This answer made me upgrade to Oxygen, and that was all I needed to make it work. Commented Apr 12, 2018 at 13:30
  • I do not have the "Terminal" submenu in Eclipse with version string "2019-06 (4.12.0)". Commented Sep 6, 2019 at 13:14
  • @tsj You need to install "TM Terminal" plugin from Eclipse marketplace. Commented Feb 4, 2021 at 8:47
10

Had the same problem. Here is my solution:

  1. Edit the /etc/paths file to include the desired additional path.

  2. For a OSX installation, run /Applications/eclipse/eclipse not /Applications/eclipse/Eclipse.app

Oliver Salzburg
89.3k65 gold badges269 silver badges311 bronze badges
answered Aug 3, 2012 at 16:04
4
  • 1
    omg number 2 on here was the solution to SO MUCH FRUSTRATION. Thanks!! Commented Oct 2, 2013 at 16:39
  • 1
    I registered to this website just so I could upvote this answer - item #2 fixed it! Commented Jul 6, 2016 at 8:28
  • Where can I find the etc/paths? Commented Apr 12, 2018 at 12:37
  • 1
    @John /etc/paths is 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". Commented May 30, 2018 at 10:56
9

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.

answered Aug 23, 2009 at 19:42
2
  • 1
    Unfortunately, this doesn't seem to work for me. Commented Nov 19, 2012 at 22:44
  • 1
    Sadly, the above link is dead and Apple has undoubtably changed this behavior. Commented Apr 12, 2024 at 14:32
7

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.

answered Aug 23, 2009 at 19:41
2
  • 3
    +1 for your final question. I'm wondering how to diagnose path issues in OS X not in bash or the Terminal. Commented Jan 21, 2010 at 0:19
  • Note for future Googlers: Apple now includes /usr/local/bin first in users' $PATH. (See here.) Commented Dec 1, 2018 at 15:47
4

If you are on Eclipse (tested with "Mars"), you could change your "Run Configuration":

  1. Click on "Run" → "Run Configurations..."
  2. Choose the appropriate run configuration on the left
  3. Now choose tab "Environment"
  4. Click on "New..."
  5. In the "Name" field, enter "PATH"
  6. Now go to your Terminal, enter "echo $PATH" and copy the result
  7. Past the result into the "Value" field
  8. Klick "OK"
  9. 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();
answered Mar 12, 2016 at 8:51
3

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

answered Jul 10, 2013 at 22:55
1
  • This one works for me, thank you very much! In my case, the path to run Eclipse is /Applications/Eclipse.app/Contents/MacOS/eclipse Commented Feb 9, 2017 at 23:24
2

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?

answered Aug 23, 2009 at 19:29
2
  • 1
    good 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? Commented Aug 23, 2009 at 19:32
  • 1
    Also I don't have a .bashrc or .bash_profile in my user directory. Commented Aug 23, 2009 at 19:33
2

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.

answered Oct 18, 2013 at 9:28
2
  • This does not seem to have anything to do with $PATH or directories in $PATH like /usr/local/bin. Could you please explain in more details? Commented 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 files Commented Oct 18, 2013 at 19:37
1

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

answered Aug 26, 2014 at 22:58
1

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.

answered Oct 30, 2016 at 7:34
0

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.

Stephen Rauch
3,29611 gold badges25 silver badges26 bronze badges
answered Apr 21, 2017 at 1:56
0

Pulling together a few answers and updating to something easy:

  1. Right-click Eclipse.app and choose "Show Package Contents"
  2. Navigate to Contents/MacOS to find "eclipse".
  3. Right-click and choose "Make Alias", or drag and drop it while holding command and option.
  4. Put the alias somewhere convenient, like back in Applications.
  5. Double-click to launch.
  6. 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.

answered Apr 6, 2018 at 2:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.