Setting Environment Variables in OS X 10.8 (Mountain Lion)

I was recently trying to install SQL Developer from Oracle and wanted the LDAP function to work, which would require the application to be aware of my ORACLE_HOME, but I could not get the application to become aware of the environment variable when I launched it from the Launcher or the Dock.

Shell Variables

For environment variables that are only going to be used in the terminal, setting them in the .bash_profile is sufficient.  I’m not totally sure how the OS X shell works, but it seems to only read the .bash_profile (doesn’t seem to read .bashrc etc.), and it reads it every time a new terminal is open.


PATH=${PATH}:${HOME}/scripts; export PATH

The problem with using the .bash_profile is that applications in the GUI are not aware of the environment variables (e.g. in my case, launching SQL Developer from the command line activated the features I wanted, but clicking the icon from the Launcher did not activate the features).

Environment Variables

There used to be a mechanism for setting environment variables prior to Mountain Lion by setting them in the ${HOME}/.MacOSX/environment.plist file, but this doesn’t seem to work in Mountain Lion.  They have to be set via launchd in /etc/launchd.conf. Unfortunately, this can’t be done at a user level at the moment (${HOME}/.launchd.conf not currently supported), so it must be done at a global level (affects all users).


setenv ORACLE_HOME /opt/oracle

Path Variables

There is one more way to set the PATH globally for all users. It can be done by adding directories that should be in the path into files under the /etc/paths.d directory.


Here is an example of a file that might be called /etc/paths.d/oracle.


12 responses to “Setting Environment Variables in OS X 10.8 (Mountain Lion)

  1. Hi,
    Great article.
    But in the Path variable example, “…file that might be called /opt/paths.d/oracle”, shouldn’t it be “…file that might be called /etc/paths.d/oracle” (not opt, etc instead)?

    • Thanks for the tip! However, I’ve noticed that setting environment variables with the .bashrc and .bash_profile only makes the shell aware and not the entire system (i.e. GUI apps).

  2. Pingback: Setting Environment Variables with Spaces in OS X 10.8 (Mountain Lion)… | Christopher Baek

    • I found the paths.d thing when I looked in the /etc/profile and saw /usr/libexec/path_helper. The man page says, “The path_helper utility reads the contents of the files in the directories /etc/paths.d…” with some other stuff. For Linux users, not such a straight-forward way to set the path…

  3. Hi, I had all my pictures in an external HD and now iPhoto asks me the rute of every pictures. I move them to another directory, and I’m wondering if I can trick the iPhoto App to think that the pictures stay in the dead external HD (but they now are in my Documents folder)

    A friend of mine tall me that in wndows, you can trick the OS to set a new path under enviroments variables, I don’t know if you can do something similar in OSX, I mean, to write a new route.

    I don’t where to ask this.

    thanx in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s