/etc/paths vs /etc/paths.d

I am curious what the purpose of the directory /etc/paths.d is. My path looks like this, first four set on /etc/paths, the last one on /etc/paths.d/50-X11


echo $PATH

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin


This is all done by Apple (Lion).


I am asking because I need to move /usr/loca/bin ahead of /usr/bin, which works fine if I edit /etc/paths. Adding to /etc/paths.d would not work for me as it seems entries in paths.d come after those in paths.


My question is which is the safest & most robust way to add to the path, systemwide (not just a .profile, etc in my home directory). I plan to start installing lots of 3rd party software and I do not want to let them touch /etc/paths.


Thank you


Posted on Jan 20, 2014 3:21 PM

Reply
12 replies

Jan 20, 2014 4:13 PM in response to unixnerd09

see: man path_helper


DESCRIPTION

The path_helper utility reads the contents of the files in the directo-

ries /etc/paths.d and /etc/manpaths.d and appends their contents to the

PATH and MANPATH environment variables respectively. (The MANPATH envi-

ronment variable will not be modified unless it is already set in the

environment.)


Files in these directories should contain one path element per line.


Prior to reading these directories, default PATH and MANPATH values are

obtained from the files /etc/paths and /etc/manpaths respectively.

Jan 20, 2014 5:27 PM in response to unixnerd09

unixnerd09 wrote:


I plan to start installing lots of 3rd party software and I do not want to let them touch /etc/paths.

Such as? It is unlikely that any of them would use /etc/paths.d. A ports package like homebrew might, but I am not familiar with them.


You would only need /usr/local to be in front of /usr if you are trying to override something. What are you trying to override?

Jan 20, 2014 6:47 PM in response to etresoft

Yes, I was able to override the emacs that came with OS X with the one I installed in /usr/local by simply editing /etc/paths. I had to do this because the build did not touch /etc/paths, which is a good thing.


I plan to experiment homebrew, macports and such, see which one fits my needs.


I guess I should rephrase my question. I would like to know what is usually done so that I know in advance where to look if a package breaks my path.


For example, I just installed a Python distribution (Canopy) and it put in ~/.profile the line "source path-to-some-script", where the script does something complicated to prepend the Canopy path the existing $PATH.


I am used to simply explicitly prepending or appending paths to $PATH in a .profile or .bashrc, .cshrc, etc file, and all this seems a bit unusual.


Thank you

Jan 21, 2014 6:14 AM in response to unixnerd09

Why not establish your desired PATH in your .bash_profile when you start a Terminal session?


Besides the security implications, there are also Mac OS X daemons and scripts that may fail if their PATH is not the expected default PATH.


Now if you ONLY put emacs in /usr/local/bin, then chances are nothing will break, but if you start putting all kinds of open source stuff in /usr/local/bin, then the chances are you will eventually break some Mac OS X background maintenance task or daemon.

Jan 21, 2014 7:35 AM in response to unixnerd09

You can just use "alias" to define "emacs" point to your new version. If tools need any supporting files they probably have some environment variable to define where they live. Having multiple versions of software is pretty common in the UNIX world.


I suggest keeping the system path the way it is. There are a whole lot of gotchyas that could get you later on down the road. Things will work initially, but if you need to make any changes (like upgrading the OS or a tool), things could get messy.

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.

/etc/paths vs /etc/paths.d

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