20

I've been struggling to get an app to run in OS X Mavericks. I finally was able to get it to run by drilling into the .app bundle and running the shell script directly. It seems that JAVA_HOME needed to be set. So I set it in my .profile in the shell, and everything works fine.

However, if I want to simply click the icon in the dock, it won't run. My guess is that this is because JAVA_HOME is not set globally. Since I'm not running the app directly from the shell, OS X doesn't know what JAVA_HOME is. It just keeps looking.

In previous versions of OS X, it seems that environment variables could be set for GUI apps by simply adding them to /etc/launchd.conf. This file doesn't seem to exist in Mavericks. How can I set a global environment variable that will work for GUI apps in Mavericks?

2 Answers 2

24

/etc/launchd.conf has never existed by default, but it does still work in 10.9.

  1. Run for example sudo nano /etc/launchd.conf.
  2. Add a line like setenv JAVA_HOME /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home. (I don't know what JAVA_HOME should actually be set to though.)
  3. Either restart or run launchctl < /etc/launchd.conf; sudo launchctl < /etc/launchd.conf and relaunch processes.

launchctl export prints variables exported by the user launchd process and sudo launchctl export prints variables exported by the root launchd process.

This method can also be used to set a default path. For example I have added this line to /etc/launchd.conf:

setenv PATH /Users/lauri/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/libexec:/usr/texbin

(I used /Users/lauri/bin instead of ~/bin because ~/bin would be /var/root/bin for programs run as root.)

3
  • 5
    +1 for explaining how to get changes in /etc/launchd.conf without restarting the system. For configuring the PATH environment variable files in /etc/paths.d/ should be used. Feb 28, 2014 at 9:59
  • 5
    Actually, /etc/launchd.conf doesn't work anymore after 10.10
    – OleGG
    Nov 9, 2014 at 2:06
  • @OleGG this remains a pain on Mac even today on Ventura :( no clear descriptions anywhere as to how we can set environment variables system wide.
    – Gautam
    Mar 31, 2023 at 4:27
0

Launchd.conf is not working/usable any further since Mac OS 10.10.

Correct way to achieve this now is through LaunchAgent scripts that get loaded at startup time. Since these scripts are horrendously tedious ( personal opinion :), I prefer using .bash_profile and automatically creating/updating these scripts.

Try this SO answer for an easier way to achieve this from your .bash_profile. Hopefully this will save you the few hours I spent trying to figure it out ( again ) for my new Mac M2

https://stackoverflow.com/questions/25385934/setting-environment-variables-via-launchd-conf-no-longer-works-in-os-x-yosemite

You must log in to answer this question.

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