Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

In Lion (and previous releases) it was in .MacOSX/environment.plist. After upgrading to 10.8, the file is still there, but the variables aren’t taking.

I’ve also tried adding them to /etc/launchd.conf and they’ll show up in Terminal, but not GUI applications (like my IDE).

share|improve this question
    
Did you reboot after changing /etc/launchd.conf? –  patrix Jul 25 '12 at 17:16
    
I did, and all the variables therein are now available in any terminal, but not present for my IDE. –  Felix Jul 25 '12 at 17:26
    
Maybe the IDE does not expose the environment to you (See my answer)? What IDE is it? is it launch directly by the Finder or Spotlight? –  halloleo Apr 15 '13 at 23:32

5 Answers 5

I know this is an old question but I thought I would point out that in Yosemite /etc/launchd.conf no longer works (as confirmed by the man page). So here is an alternative.

Launch AppleScript Editor, enter a command like this:

do shell script "launchctl setenv variablename value"

(add as many lines as you like)

Now save (⌘S) as File format: Application. Finally open System SettingsUsers & GroupsLogin Items and add your new application.

share|improve this answer
    
Note that it might nor work with other apps that are opened as Login items and perhaps those you open quickly after login –  Mark Sep 20 at 17:04
    
This worked for me. Thank you so much. This has been driving crazy all day! –  wholladay Oct 22 at 2:06

Setting environment variables in /etc/launchd.conf is the way to go: Every application launched after a reboot by local shells, Finder or Spotlight inherits these variables - I have tested this extensively with Mountain Lion 10.8.3.

2 caveats:

share|improve this answer

Try launchctl setenv NAME VALUE. I don't know if/what it does differently from editing launchd.conf, but it works for me in both Terminal and GUI apps. More details.

Note this doesn't survive across a reboot. Here's a way to fix that.

share|improve this answer
1  
That's quite a long page you are linking to here. Where exactly is the relevant part? Could you include it directly into your answer to make it easier for everybody? –  patrix Mar 17 '13 at 8:24
2  
oops, good point, thought i'd included more of a fragment in that url. fixed. –  ryan Mar 18 '13 at 14:30
    
The way to survive across a reboot given there uses the environment.plist which stopped working under Lion –  Mark Sep 20 at 17:06

As you have discovered, the use of environment.plist file is no longer followed, the variables stored in Info.plist as LSEnvironment strings are only set by launchd.

You cannot depend on them to set a general environment variable that the terminal will set if you call your program from the terminal/shell directly. The good news is the open -a command does trigger launchd to do the launching, so the variables will be set consistently for the app environment if not for the local shell environment.

share|improve this answer
up vote 16 down vote accepted

I asked this question on the Apple Developer Forums as well and got back this, official response.

Change the Info.plist of the .app itself to contain an "LSEnvironment" dictionary with the environment variables you want.
~/.MacOSX/environment.plist is no longer supported.

share|improve this answer
1  
Where is that located? –  raxacoricofallapatorius Dec 12 '12 at 19:10
    
It would be useful to provide a link to a more specific example. –  Blaisorblade Feb 2 '13 at 4:41
    
Update: I tried changing that file, after figuring out the syntax (I think), but it does not work at all for me. –  Blaisorblade Feb 2 '13 at 5:04
2  
There will be an Info.plist per application in WhatEver.app/Content/Info.plist. You can edit it with XCode. Click the "+" on the Information Property List and add a dictionary called LSEnvironment. If you type it correctly it will rename it to Environment variables. Then you click the "+" by that for each environment variable you want to add. –  Felix Feb 6 '13 at 1:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.