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.

Google search reveals that "/etc/environment" can be used in OS X to set global environment variables (like JAVA_HOME etc, in key-value pairs). I have tried to add following string to this file on OS X Lion:

sudo sh -c 'echo "FOO=bar" >> /etc/environment'

But after rebooting OS X, echo $FOO displays empty string.

Am I doing something wrong or is the information on the internet misleading and "/etc/environment" can't be used in OS X, and am I limited to "/etc/launchd.conf"?

share|improve this question
1  
Where does it say /etc/environment can be used? –  Mark Jul 30 '12 at 11:58
    
@Mark UNIX has different notion for global environment variables? Is it documented somewhere? –  Eye of Hell Jul 30 '12 at 13:01
    
I meant all the /etc/environment comments are by Linux people my IOSX does not have /etc/environment and you should not alter Apple supplied files in /etc –  Mark Jul 30 '12 at 22:01
    
@EyeofHell, would you mind rephrasing the question to "How can I set environment variables globally'? –  patrix Jul 31 '12 at 20:22

3 Answers 3

up vote 2 down vote accepted

/etc/environment may work in Linux but doesn't in OS X. There exist other options to accomplish similar results though.

Additional paths

Additional paths can be added in /etc/paths.d by creating a text file there listing one path component per line (e.g. sudo echo /usr/local/superbin > /etc/paths.d/superbin).

Other environment variables

As more or less everything is controlled by launchd these days global environment variables can be specified directly in /etc/launchd.conf as described in this StackOverflow answer.

share|improve this answer
1  
For people on Yosemite: Please note that /etc/launchd.conf is no longer processed. There is therefore no remaining way to set environment variables automatically at startup for Dock/Spotlight-launched applications (really). –  Laird Nelson Oct 17 at 20:54

Another solution for feeding launchd, and a discussion of the approaches in the StackOverflow answer mentioned, is provided at superuser by yours truly.

share|improve this answer
    
Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. –  Daniel Lawson Sep 21 '12 at 11:25
    
@DanielLawson I am not sure if the part of the answer above that links to stackoverflow by patrix is more self sufficient then my bit. What do you suggest that I should add? –  Percival Ulysses Sep 21 '12 at 23:32
    
It isn't, but the rest of his answer contains stand-alone answers. What should you include? Some of the great content you posted on SO. –  Daniel Lawson Sep 21 '12 at 23:35
    
Answer from Patrix on the same point contains: server + conf. file. It is a good approach of a self sufficient answer without crossing the frontier of plagiarism :). –  daniel Azuelos Aug 7 at 9:58

You can use /etc/environment on OSX Yosemite, but you need to set up the daemons slurping the file into the environment at start up yourself.

See this stackoverflow answer for helpful and rather extensive details.

Warning: In order to go with the answer above, your /etc/environment needs to look different to yours. Be aware of this.

share|improve this answer

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.