How to use /etc/paths.d to add executable files to my path?

Solution 1:

Have you started a new login shell since adding the new file for ImageMagick? The setting of the path from paths.d entries is done in /etc/profile and /etc/csh.login, so you need to start a new shell for the new entries to take effect.

OS X uses path_helper to set the path based on the files in /etc/paths.d - you can always call it manually (assuming a Bourne-like shell here):

$ eval `/usr/libexec/path_helper -s`

Solution 2:

Running

echo /opt/ImageMagick/bin|sudo tee /etc/paths.d/ImageMagick;bash -l;echo $PATH

adds /opt/ImageMagick/bin to PATH on my installation.

Are you overriding PATH in some other place like ~/.bash_profile?

The paths in /etc/paths.d/ are added to the path by /usr/libexec/path_helper, which is run from /etc/profile, /etc/zsh.env, and /etc/csh.login. path_helper is not run by graphical applications or when bash is invoked as a non-login shell.

You can also set a default PATH in /etc/launchd.conf:

  1. Run for example setenv PATH /Users/Administrator/.rbenv/shims:/Users/Administrator/.rbenv/bin:/Users/Administrator/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/ImageMagick/bin|sudo tee -a /etc/launchd.conf.
  2. Either restart, or run launchctl</etc/launchd.conf;sudo launchctl</etc/launchd.conf and relaunch processes.

I prefer changing the path in /etc/launchd.conf, because it also affects programs that are not started from shells, like text editors and programs started by launchd jobs.