8

I'd like to set the PATH shell variable for all users, but could not find where it is defined.

Having no export PATH in my .bash_profile, I have this:

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

Where is this the PATH shell variable defined?

3 Answers 3

12

On a shell level, the PATH variable is set in /etc/profile by calling /usr/libexec/path_helper. To add your own paths, you can add files with a path in it to /etc/paths.d/:

$ ls -l /etc/paths.d
total 8
-rw-r--r--  1 root  wheel  13 Jul 22 07:02 50-X11
-rw-r--r--  1 root  wheel  12 Aug 13 14:12 TeX
$ cat /etc/paths.d/TeX 
/Library/TeX/texbin

That's the safer way than editing /etc/profile, /etc/paths or any other system-provided file which may get overwritten with the next OSX upgrade.

0
0

A possibly more complete list of places where PATH might be (re)defined on macOS:

  1. /etc/paths
  2. entries under /etc/paths.d
    • bash: /etc/profile /etc/bashrc, /etc/bashrc_Apple_Terminal ~/.bashrc
    • zsh: ~/.zshenv /etc/zprofile /etc/zshrc /etc/zshrc_Apple_Terminal ~/.zshrc ~/.zprofile

/usr/libexec/path_helper collects entries from /etc/paths, /etc/paths.d, and then the shell — bash, zsh, etc — applies on top of that its own customizations.

Keep in mind that each of the files in the chain might include more files, so watch closely for lines that start with . some-file or source some-file. For example, you might find something like source ~/.bash_profile in your ~/.bashrc.

4
  • path_helper only reads /etc/paths and the files in /etc/paths.d, not the shell-specific startup files.
    – nohillside
    Feb 29 at 20:17
  • @nohillside: running /usr/libexec/path_helper -s on ventura 13.5 includes all the extra PATH additions from ~/.zshrc
    – ccpizza
    Feb 29 at 20:22
  • Not according to path_helper.c, see line 243. Try PATH= /usr/libexec/path_helper -s to start with an empty path, and just see the things path_helper adds :-)
    – nohillside
    Feb 29 at 20:37
  • indeed, that matches with man path_helper; answer updated, thanks!
    – ccpizza
    Feb 29 at 20:46
-1

Well, if you really wanted to OVERWRITE the path, you could just set the new one in /etc/launchd.conf. There is a similar question here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .