Currently Being Moderated

Tip: How to setup Environment variables for RubyMine on Mac OS X

VERSION 9

Created on: Aug 6, 2009 3:05 PM by Roman.Chernyatchik - Last Modified:  Jul 12, 2011 1:52 PM by Eugene Toporov

Mac OS X applies .bash_profile and .profile only for Terminal.app environment and  Apple's technical documentation suggests using ~/.MacOSX/environment.plist for other applications. So, by default  PATH value will differ for RubyMine and the console.

 

  • MacOS 10.6 or later

We recommend to manage your environment variables using free Enviroment Variables preference pane instead of environment.plist manual editing.

 

  • MacOS < 10.6

Unfortunately, the "environment.plist" approach doesn't always work on MacOS < 10.6, e.g if you start RubyMine from Spotlight the environment is not applied.

Thus real solution is to set your environment variables in /etc/launchd.conf (thanks to David Goudreau for this tip). For detailed description please read Mac OS X Global Environment Variables article.

 

So you should:

1. Open /etc/launchd.conf file (e.g. $sudo nano /etc/launchd.conf)

2. Then set correct PATH env variable

setenv PATH /Users/romeo/.gem/ruby/1.8/bin:/opt/local/bin:/opt/local/sbin:/opt/local/libexec/git-core:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

 

3. Set other env variables for RubyMine if necessary

4. Save changes

5. Reboot

 

P.S: If you always launch RubyMine using Dock or QuickSilver and do not use Spotlight you can install Enviroment Variables preference pane and use it instead of the manual environment.plist editing.

 

NB: Please don't miss "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" in the end of PATH value, because PATH=...:$PATH doesn't work here.

Average User Rating
(0 ratings)




Scott Sims Scott Sims  says:

I have been looking for a way to do this without rebooting.  Is there a way to rerun launchd.conf without rebooting?

John Firebaugh John Firebaugh  says:

As of MacOS 10.6, the ~/.MacOSX/environment.plist approach works fine for applications launched from Spotlight and it's not necessary to edit /etc/launchd.conf.

Roman.Chernyatchik  Roman.Chernyatchik  says in response to John Firebaugh:

John, thank you, we've updated the documentation.


David Jensen David Jensen  says:

This appears to not be working for me. I'm running RubyMine 3.0.1 and Mac OS X 10.6.6. My Gemfile has a gem that requires a git repo clone. I've updated my environment vars as described above but when I try a "bundle install" from within RubyMine, I get the following error:

 

"sh: git: command not found"

 

Any ideas?

Roman.Chernyatchik  Roman.Chernyatchik  says in response to David Jensen:

David, did you re-login after it?

David Burrows David Burrows  says:

Can anyone explain how best to set this up when using RVM?

rslifka rslifka  says:

The preferences pane linked above is broken, pressing Save does nothing and it does not save your environment variables.

Randy Walker Randy Walker  says in response to rslifka:

The preference pane works for me just fine on OSX 10.6.6.  After adding the PATH key/value pair and clicking save, I can now see ~/.MacOSX/environment.plist which contains the PATH key/value pair I entered in the pref pane.   Just in case someone doesn't know, the dot at the beginning of ".MacOSX" makes the folder hidden unless you go into terminal and type "ls -a" or "ls -al" to display hidden files/dirs.

rslifka rslifka  says in response to Randy Walker:

Glad to hear the preferences pane works for you Wish it worked for me (i'm on 10.6.6 as well)

Randy Walker Randy Walker  says in response to rslifka:

I have plenty of other RubyMine stuff that isn't working for me, so we probably balance each other out

Roman.Chernyatchik  Roman.Chernyatchik  says in response to Randy Walker:

Preference pane warns that changes will be applied after next login in MacOS. By the way run a simple script from RubyMine which outputs ENV["PATH"] - it will allow to check actual PATH env variable settings. The pref. pane works on my mac 10.6.6.

Basil Borun Basil Borun  says in response to rslifka:

Check the ownership of ~/.MacOSX. If you don't own it, then you cannot write to

environment.plist unless you are logged in as the owner.

 

On my system, ~/.MacOSX was owned by root. Try the following from Terminal:

 

> sudo chown -RF 'yourUsername' ~/.MacOSX

Randy Walker Randy Walker  says in response to Basil Borun:

@Basil:  Are you using the Environment Variables system preference pane?   I would think it would create the ~/.MacOSX folder correctly, no? 

Basil Borun Basil Borun  says in response to Randy Walker:

Yes, I am using Environment Variable Preference Pane 1.3 on a recent fresh installation of Mac OS X 10.6.6 and no, it obviously doesn't create the ~/.MacOSX folder correctly.

rslifka rslifka  says in response to Basil Borun:

Yep, that did the trick!  it was indeed owned by root.  Once I chown'd it, the preference pane correctly writes the file.

Gam  Gam  says:

Since with can't chain the PATH assignment (with PATH = ..., $PATH), how can we be sure that we don't erase values previously assigned to PATH?

Maybe /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" is not enough?!?

Doug Puchalski Doug Puchalski  says in response to Gam:

This all seems rather difficult. Why is there not a system setting within the app for the path? Not to mention, there are other dependencies such as RVM that cannot be set system wide.

Doug Puchalski Doug Puchalski  says in response to Roman.Chernyatchik:

Could you follow-up on this thread? This is a real problem, and the system settings option is not effective or practical.

 

The post http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/3756686#3756686 seems to imply that "launchctl setenv PATH $PATH" in your profile should do the trick. Following that with "launchctl getenv PATH" does in fact show that it's updated. But when I run an irb console in RubyMine, I'm seeing some other path that I can't be sure where it's coming from.

J. Pablo Fernández J. Pablo Fernández  says:

The Environment Variable pane link doesn't work anymore. It can be found here: http://www.epikentros.net/Main/Mac_Software.html

Anthony Burton Anthony Burton  says:

I agree with Doug that this seems like it should be more of a priority and it's a little hard to comprehend why there's no "add to path" capability in Settings, but for myself I was able to work around this fairly easily. I will note that I'm on OS X 10.6.8, using RVM and Git via Homebrew. I found after much messing about that /usr/local/bin was not being added to PATH, and while none of the other methods worked for me (some gave really bizarre results which I won't bother to share), I was able to simply symlink git in /usr/bin and get back to work.

 

ln -s /usr/local/Cellar/git/1.7.6/bin/git /usr/bin/git

 

Hope that helps someone.

Eric Theise Eric Theise  says in response to Anthony Burton:

Anthony, sometimes the simplest solutions are the best.  Helped me, thank you.

 

I do wish there were a way to view the path as RubyMine sees it, and to add to it.  I wasn't really sure what to do with the Environment Variable Preference Pane.

Ian Lesperance Ian Lesperance  says:

On OS X 10.7.2 with RubyMine 3.2.4, the only thing we found to work was editing (or creating) /etc/launchd.conf as described above.

Ian Lesperance Ian Lesperance  says:

When setting the PATH environment variable using /etc/launchd.conf, be careful what value you use. We found that just using the PATH you see in Terminal had unintended consequences. To fix it, we had to remove /etc/launchd.conf, restart our machine, then run `launchctl getenv PATH`, and then use that value in /etc/launchd.conf, appending what we needed to it.