PATH env variable on Mac OS X and/or Eclipse

17

8

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

Jason S

Posted 2009-08-23T19:21:07.940

Reputation: 5 983

Answers

6

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.

Jason S

Posted 2009-08-23T19:21:07.940

Reputation: 5 983

Note for future Googlers: Apple now includes /usr/local/bin first in users' $PATH. (See here.)

– Telemachus – 2018-12-01T15:47:25.403

2+1 for your final question. I'm wondering how to diagnose path issues in OS X not in bash or the Terminal. – fideli – 2010-01-21T00:19:51.833

10

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.

Ted Naleid

Posted 2009-08-23T19:21:07.940

Reputation: 1 059

1Unfortunately, this doesn't seem to work for me. – thSoft – 2012-11-19T22:44:08.250

9

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.

Martin Peter

Posted 2009-08-23T19:21:07.940

Reputation: 191

Best solution, solves the problem just by changing eclipse configuration in GUI. – pXel – 2017-09-12T12:22:20.277

This answer made me upgrade to Oxygen, and that was all I needed to make it work. – John – 2018-04-12T13:30:31.117

I do not have the "Terminal" submenu in Eclipse with version string "2019-06 (4.12.0)". – tsj – 2019-09-06T13:14:43.550

8

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

user150161

Posted 2009-08-23T19:21:07.940

Reputation: 81

1I registered to this website just so I could upvote this answer - item #2 fixed it! – Iftah – 2016-07-06T08:28:22.890

Where can I find the etc/paths? – John – 2018-04-12T12:37:39.027

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". – Sufian – 2018-05-30T10:56:02.720

1omg number 2 on here was the solution to SO MUCH FRUSTRATION. Thanks!! – Tommy – 2013-10-02T16:39:10.547

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();

Mike

Posted 2009-08-23T19:21:07.940

Reputation: 41

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?

derobert

Posted 2009-08-23T19:21:07.940

Reputation: 3 366

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 – 2009-08-23T19:32:39.960

1Also I don't have a .bashrc or .bash_profile in my user directory. – Jason S – 2009-08-23T19:33:26.323

2

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

Kathy

Posted 2009-08-23T19:21:07.940

Reputation: 21

This one works for me, thank you very much! In my case, the path to run Eclipse is /Applications/Eclipse.app/Contents/MacOS/eclipse – Tsung-Ting Kuo – 2017-02-09T23:24:05.410

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.

dirk

Posted 2009-08-23T19:21:07.940

Reputation: 21

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? – pabouk – 2013-10-18T10:00:46.897

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 – Jason S – 2013-10-18T19:37:55.103

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.

bluearrow

Posted 2009-08-23T19:21:07.940

Reputation: 111

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

kristi

Posted 2009-08-23T19:21:07.940

Reputation: 193

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.

Vince C

Posted 2009-08-23T19:21:07.940

Reputation: 1

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.

Heath Raftery

Posted 2009-08-23T19:21:07.940

Reputation: 291