Last weekend I upgraded my Mac to OS X Mountain Lion. Everything went pretty smoothly. I had to re-install Java, but that happened automatically when I first tried to run it. I also had to re-install Xcode, but the App Store made that pretty painless.

But when I ran a build from inside Xcode it failed because it couldn’t find coffee. Right. Because Xcode doesn’t have access to the PATH set in my shell.

The previous recommendation for setting your PATH for all apps, including GUI ones, on Mac OS X has been to use ~/.MacOSX/environment.plist. With Mountain Lion, that’s stopped working. Nice.

After a bit of googling, and a couple of restarts (really? I thought we were supposed to be living in the future?) I got this fixed.

  1. For environment variables to be available to all apps, they need to be set by /etc/launchd.conf.

  2. This file is a list of launchctl commands; it is not a shell script. Therefore, it doesn’t have any shell environment variable substitution.

  3. To set an environment variable use something like:

    setenv VAR "custom value"
  4. But this will overwrite any existing value, so if you just want to add something to the PATH you’ll need to include the original value.

  5. I wanted to add /usr/local/bin, so the following worked:

    setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

    That is, /usr/bin/:/bin:/usr/sbin:/sbin is the entirety of the default Mac OS X PATH.

  6. The /etc/launchd.conf file is only read at startup, so you’ll need to restart for changes to take affect.

Hope that helps. Interesting fact: if you accidentally clear your PATH your Mac will pretty much still work. Except the screensaver won’t start.