17

I am trying to use /etc/paths.d to add an executable to my path variable but I have no success so far.

The full path of the executable file is: /opt/ImageMagick/bin/convert

/etc/paths.d contains two files: 40-XQuartz and ImageMagick

The 40-XQuartz contains one line: /opt/X11/bin
The ImageMagick contains one line: /opt/ImageMagick/bin

My echo $PATH gives:

/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:/usr/local/bin:/opt/X11/bin

So it seems that only the first file (40-XQuartz) does its job. The permissions of the two files (40-XQuartz and ImageMagick) are exactly the same so my question is why the first one works and the second one is not.

I am running OS X Mavericks.

grg
  • 192,762
  • 43
  • 337
  • 460
skiabox
  • 937
  • 6
  • 11
  • 23

3 Answers3

22

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`
mjturner
  • 4,895
  • 24
  • 31
  • Of course I have started a new shell.I even restarted my mac. – skiabox Apr 27 '14 at 17:10
  • new login shell worked for me – incandescentman Sep 09 '16 at 20:23
  • @mjturner when using your command it reorders my paths putting paths I have in `.bash_profile` below the paths that are in `etc/paths.d`. Is there a way around that? – John Aug 28 '20 at 04:26
  • @John What do you have in `.bash_profile'? You may need to adjust how you set `PATH` so that your preferred directories are first. – mjturner Aug 28 '20 at 12:07
  • 1. `PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin` 2. `export PATH` 3. `PATH=$PATH:/usr/local/opt/nano/bin` 4. `PATH=$PATH:/usr/local/sbin` – John Aug 28 '20 at 13:28
  • From the man page. `NOTE The path_helper utility should not be invoked directly. It is intended only for use by the shell profile.` – John Aug 30 '20 at 23:21
4

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.

Lri
  • 101,672
  • 19
  • 221
  • 272
0

Awesome, I was just playing around with adding ImageMagic to my Mac. Not only do you need ImageMagick/bin in your PATH, you also need an environment variable set, or added to:

To test you can create it manually with:

export DYLD_LIBRARY=".:/opt/ImageMagic/lib"

Information for setting an environment variable for Mac OS can be found here, Setting environment variables in OS X?

Greenonline
  • 1,233
  • 2
  • 18
  • 26
Tony
  • 1