In OSX Yosemite, why can I set many environment variables for GUI apps, but cannot set the specific variable PATH

Solution 1:

PATH in Yosemite can and should be set within /etc/paths file. Just add your path to the end of this file:

/usr/bin
/bin
/your/custom/path

/etc/environment script in original post provides support for PATH variable in GUI applications (tested with Emacs).

Solution 2:

This puzzled me for a long time (well, the last couple of hours). In the end I ran into this bug report, which seems to exactly describe my problem (I'm not sure to what extend it's related to your problem, but there seems to be a bug in Yosemite/launchd in combination with PATH and scripts such as python:

http://www.openradar.me/18945659

The solution seems to be to start a shell script which then starts the python. Not really what I like, but it's the way it is....

Solution 3:

The problem is that launchd appends another PATH variable instead of replacing the one in the environment. Most programs use getenv which always returns the first occurence of a variable, shells instead iterate through all environment variables and import them as local variables thus overwriting previous instances with the last one.

This is obviously a bug in launchd, environment variables passed to a program should be unique.