Set systemwide variable with /etc/launchd.conf does not work in 10.10

Hi,


before i upgraded my system, i set in file /etc/launchd.conf some variables. I need this for the Shell, Eclipse and some other tools.


user@osx10-10:~$ cat /etc/launchd.conf

setenv M2_HOME /opt/maven

setenv MAVEN_OPTS "-Xmx2048m -Dmaven.surefire.debug=-Xmx2048m"

user@osx10-10:~$


With Mavericks there was no problem, since Yosemite no Variables are set.

Also when i try to set it manually with launchctl setting xxxxx xxxx, no variable is set.


Does anyone has a workaround for me?


Regards


Joerg

MacBook Pro with Retina display, OS X Yosemite (10.10)

Posted on Oct 17, 2014 11:03 AM

Reply
10 replies

Oct 20, 2014 1:02 PM in response to Luke_Sensei

This does not work. I need to add environment variables so that they are available in Xcode. Xcode does not pick them up from .bash_profile.


In my case I need to run Ant from Xcode. I do not want to hardcode path to Ant because different team members have ant installed in different locations. I need to run ant like this "ant build.xml". On Mavericks, I simply added Ant path to PATH environment variable and Xcode picked it up. I need a way to do the same thing in Yosemite. Here are the entire contents of my launchd.conf:


setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/alex/Dev/apache-ant-1.9.2/b in

setenv ANT_HOME /Users/alex/Dev/apache-ant-1.9.2

setenv ANT_OPTS -Xmx512M

Oct 20, 2014 2:20 PM in response to alexfromtarzana

Alex It should work . by the way your PATH variable should be placed in /etc/paths like this :

/usr/bin

/bin

/usr/sbin

/sbin

/usr/local/bin

/Users/alex/Dev/apache-ant-1.9.2/bin

Note after each line there is a return key

As for environment variables open your ~/.bash_profile and place the.

export ANT_HOME = /Users/alex/Dev/apache-ant-1.9.2

launchctl setenv ANT_HOME $ANT_HOME

export ANT_OPTS = -Xmx512M

launchctl setenv ANT_OPTS $ANT_OPTS


make sure you save and restart all applications that need to read environment variables. I faced the same problem with intelliJ accessing M2_HOME


As a side note : consulting the man pages of launchctl(1)


DEPRECATEDANDREMOVEDFUNCTIONALITY

launchctl no longer has an interactive mode, nor does it accept commands from stdin. The

/etc/launchd.conf file is no longer consulted for subcommands to run during early boot time; this func-

tionality was removed for security considerations. While it was documented that $HOME/.launchd.conf

would be consulted prior to setting up a user's session, this functionality was never implemented.


launchd no longer uses Unix domain sockets for communication, so the LAUNCHD_SOCKET environment vari-

able is no longer relevant and is not set.


launchd no longer loads configuration files from the network

Oct 20, 2014 3:33 PM in response to Luke_Sensei

Hi Luke,


Thanks for trying to help, but it still doesn't work. I didn't know about /etc/paths file and I thought it might help. I made all the changes you recommended and restarted the computer. The changes had no effect on Xcode. I think that IntelliJ may be doing things differently because it's a Java process. Maybe it's picking things up from shell environment. When I run my Ant build step in Xcode, it prints its environment and I don't see ANT_HOME, ANT_OPTS, or any changes to PATH. From some research I believe that /etc/paths is only used in shells and is not used by GUI programs.

Oct 22, 2014 11:28 AM in response to Luke_Sensei

Thanks for your help, Luke. I got it working.


I was only looking at environment variables printed in Xcode build log, which might not be all of them. When I echoed $ANT_HOME from the shell script that runs Ant, I saw the correct value. I can also confirm that "launchctl setenv" statements ARE required. The shell script launched by Xcode DOES NOT pick up standard "exported" variables from .bash_profile.

At this point I still had a problem because "ant" command was not in the path. Rather than trying to figure out how Xcode constructs its PATH variable, I decided to settle for a simple work-around. I just use ANT_HOME to construct the full path to ant, like this:

ANT=$ANT_HOME/bin/ant

$ANT -f ${PROJECT_DIR}/../build/build-xcode.xml

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Set systemwide variable with /etc/launchd.conf does not work in 10.10

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.