Currently Being Moderated

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

VERSION 11

Created on: Aug 6, 2009 3:05 PM by Roman.Chernyatchik - Last Modified:  Mar 19, 2012 3:38 PM by Serge Baranov

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.

Ryan Warnick Ryan Warnick  says:

I had to set the env variable in /etc/launchd.conf for OSX 10.7.4.  ~/.MacOSX/environment.plist had been working in 10.7.3.

Anton Koch Anton Koch  says:

really? is there no other way? i have homebrew with imagemagick and paperclip can't find identify (it works from the terminal, so the issue is clear) but i can't see why i have to fumble with a system wide file for various apps (launchd.conf) and set up env variables that point to my user folder's gem folder... this seems like a can of worms to me (plus it is a pretty ugly requirement in the first place).

David Jensen David Jensen  says:

As of 10.8 this technique no longer works. My git path is on the command line path and in the "Environment Variables" of System Preferences. Prior to 10.8, this worked just fine. Something apparently changed in Mountain Lion.

David Handel David Handel  says in response to David Jensen:

I also upgraded to 10.8.  Git no longer worked, presumably my path was incorrect.  I downloaded and reinstalled git.  The instructions stated "This installs

git to /usr/local/git".  But when I add that path in the prefences of Rubymine and test, it fails.  How can I fix this and get git connected to Rubymine?
Serge Baranov Serge Baranov  says in response to David Handel:

/usr/local/git is a directory, use /usr/local/git/bin/git

David Handel David Handel  says in response to Serge Baranov:

It worked.  Thanks Serge.

Ryan Warnick Ryan Warnick  says:

It appears as though RubyMine local environment variables are working in RubyMine 4.5.2 on Mountain Lion.  So, depending on the environment variable that you are trying to set and the usage context, this may be a nice alternative to setting it in launchd.conf or some other workaround.  In my case, I set DYLD_LIBRARY_PATH as an environment variable under the Run/Debug configuration that I want it for.

Paulo Henrique Castro Paulo Henrique Castro  says in response to Ryan Warnick:

The only way I could had my RubyMine working on my Mountain Lion was puting the

DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH under the Run/Debug config.
John Firebaugh John Firebaugh  says:

As of MacOS 10.8,

~/.MacOSX/environment.plist is no longer supported. You have to change the application Info.plist instead. http://apple.stackexchange.com/questions/57385/

Serge Baranov Serge Baranov  says in response to John Firebaugh:

Changing Info.plist is not recommended, see http://stackoverflow.com/a/13588544/104891 . The easiest way is to run RubyMine from Terminal:

 

open -a /Applications/RubyMine.app/

Stefan Hendriks Stefan Hendriks  says:

In OS X 10.8 you cannot set the environment.plist , therefor Serge's sollution works best.

 

You can also set the PATH in your environment vars in RubyMine itself. I have written a little blog about it: http://stefanhendriks.wordpress.com/2012/12/27/os-x-10-8-mountain-lion-path-settings-not-picked-up-in-rubymine/