Upgraded to Leopard : Making use of /etc/paths.d and path_helper
24 Jan 2008In Leopard, Apple has introduced a new mechanism for managing and maintaining your system path ($PATH).
Previously (and in most current Linux environments) paths were managed by updating the PATH environment variable directly in either the system profile (/etc/profile) or your local profile (~/.bash_profile).
Commonly you had entries like:
export JAVAHOME = /usr/lib/j2se/jdk1.5.013/ export PATH=$PATH:$JAVA_HOME/bin ...
In Leopard, you no longer have to modify the profile to make adjustments to system paths. Instead, you can put a simple text file containing a path entry (or entries) into /etc/paths.d/.
Each line in this file will be interpreted as a path and added automatically to the system path.
macos-gls000120:~ ajordens$ ls -al /etc/paths.d/ total 40 drwxr-xr-x 7 root wheel 238 Jan 22 18:51 . drwxr-xr-x 105 root wheel 3570 Jan 23 11:59 .. -rw-r--r-- 1 root wheel 13 Sep 23 20:53 X11 -rw-r--r-- 1 root wheel 16 Jan 22 18:58 groovy -rw-r--r-- 1 root wheel 15 Jan 22 18:58 maven -rw-r--r-- 1 root wheel 20 Jan 22 18:58 postgresql -rw-r--r-- 1 root wheel 15 Jan 22 18:58 scala
macos-gls000120:~ ajordens$ cat /etc/paths.d/scala $SCALA_HOME/bin
It’s up to you whether you include an environment variable or specify the full path.
Enter Leopard
In order to take advantage of this new feature, your /etc/profile needs to invoke /usr/libexec/path_helper. Depending on your upgrade path to Leopard, your profile may or may not have been automatically updated.
Unfortunately mine wasn’t and I couldn’t find a definitive post telling what changes I had to make to the profile. I decided to write the procedure up so that anyone else wanting to take advantage of paths.d and path_helper could do so.
macos-gls000120:~ ajordens$ cat /etc/profileSystem-wide .profile for sh(1)
if [ "${BASH-no}" != "no" ]; then [ -r /etc/bashrc ] && . /etc/bashrc fi
export ANT_OPTS="-Xmx256M"
export POSTGRESQLHOME="/opt/local/lib/postgresql82" export CONFBASE=/usr/local/src/confluence-2.6.2 export HADOOPHOME=/usr/local/src/hadoop-0.15.2
export GROOVYHOME=/usr/local/src/groovy-1.5.1 export SCALAHOME=/usr/local/src/scala-2.6.0-final export MAVEN_HOME=/usr/local/src/maven-2.0.7
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/"
if [ -x /usr/libexec/pathhelper ]; then eval `/usr/libexec/pathhelper -s` fi
That’s basically it. I put the path_helper invocation at the end of the profile because I wanted to be able to substitute environment variables.