When I type $PATH, among the list of values I see some are from /etc/paths
and /etc/paths.d
, but there are also links to python frameworks. Where does it read these from?
2 Answers
When you log on to your computer, the loginwindow.app sets up a basic environment which includes $HOME
, $SHELL
, $TMPDIR
, $LOGNAME
, $USER
, and $PATH
. The environment may also be altered by launch daemons or agent. Or by extending the PATH variable within launchd
. Typically, the PATH variable is set to the hard coded PATH variable in the kernel.
sysctl user.cs_path
user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin
When you start the terminal emulator, by default, it will call login
- login -pf <yourname>
which will setup only those environment variables that have not already set (see man login
).
Your shell- $SHELL
then reads the appropriate file in /etc
that calls path_helper
. path_helper
takes the PATH variable that is already set, reads /etc/paths
, removes duplicates in the current PATH and orders the PATH variable as set in /etc/paths
, then reads the files within /etc/paths.d
adds those to the PATH variable, and then adds any paths that were in the original PATH which haven't already been added..
Finally, your $SHELL reads the appropriate rc file for a login shell in your home directory.
A program called path_helper
is run from various /etc/*
shell rc files by default.
$ grep path_helper /etc/* 2>/dev/null
/etc/csh.login:#if ( -x /usr/libexec/path_helper ) then
/etc/csh.login:# eval `/usr/libexec/path_helper -c`
/etc/profile:#if [ -x /usr/libexec/path_helper ]; then
/etc/profile:# eval `/usr/libexec/path_helper -s`
/etc/zprofile:#if [ -x /usr/libexec/path_helper ]; then
/etc/zprofile:# eval `/usr/libexec/path_helper -s`
$
This is obviously not the default; I've disabled path_helper
and manage PATH
in my own rc files.