0

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"?

4
  • 1
    Where does it say /etc/environment can be used?
    – mmmmmm
    Commented Jul 30, 2012 at 11:58
  • @Mark UNIX has different notion for global environment variables? Is it documented somewhere?
    – grigoryvp
    Commented Jul 30, 2012 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
    – mmmmmm
    Commented Jul 30, 2012 at 22:01
  • @EyeofHell, would you mind rephrasing the question to "How can I set environment variables globally'?
    – nohillside
    Commented Jul 31, 2012 at 20:22

3 Answers 3

2

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

1
  • 3
    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). Commented Oct 17, 2014 at 20:54
1

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

4
  • 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
    Commented Sep 21, 2012 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? Commented Sep 21, 2012 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
    Commented Sep 21, 2012 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 :).
    – athena
    Commented Aug 7, 2014 at 9:58
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .