The paths in /etc/paths
and /etc/paths.d/*
are typically added to PATH
by path_helper. path_helper
is run from /etc/profile
, so it is run when bash is invoked as an interactive login shell, but not when bash is invoked as a non-login shell or a non-interactive shell.
/etc/paths
contains /usr/local/bin
at the end by default, and /etc/paths.d/
is empty by default.
Terminal and iTerm 2 open new shells as login shells by default, and the shell opened when you ssh to your computer is also a login shell. Many terminal emulators on other platforms, tmux
, and the shell mode in Emacs open new shells as non-login shells though.
I have added this line to /etc/launchd.conf
:
setenv PATH ~/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/libexec:/usr/texbin
It changes the value of PATH
of the root launchd process. The value is inherited by all other processes, including per-user launchd processes. You can apply changes to /etc/launchd.conf
by restarting, or by running launchctl < /etc/launchd.conf; sudo launchctl < /etc/launchd.conf
and relaunching processes.
On OS X, ~/.profile
is not read when you log in graphically. If both ~/.bash_profile
and ~/.profile
exist, bash does not read ~/.profile
either.
~/.MacOSX/environment.plist
stopped working in 10.8.
"In OS X, additionally, there is path_helper which reads the contents of /etc/paths.d and appends those to your path." No,
path_helper
is not called for interactive non-login shells (nor non-interactive shells). It is called for interactive login shells, by/etc/profile
actually. – Maggyero – 2019-09-15T15:34:27.193Thanks for the concise, and informative answer. So I guess I kind of understand, which scripts/artifacts influence the $PATH then. So does this mean the
/etc/profile
is a script mainly used by bash? I don't have experiences with other shells, but I assume they follow a different structure? – Psycho Punch – 2013-10-03T15:38:48.547The
/etc/profile
is used by most (all? Not 100% sure) shells. That's why it's a good choice to put things in that you want everywhere, like PATHs. Bash reads.bash_
files while Zsh for example reads.zshrc
in addition to others. It depends on the shell. – slhck – 2013-10-03T15:46:10.693