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"?
Best Answer
/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.