In zsh on mac OS, where is the source of $PATH? I cannot find it in .zshrc
42,859
Solution 1
There are many possibilities, but some are likelier than others. When starting Zsh, it will source the following files in this order by default:
-
/etc/zsh/zshenv
Used for setting system-wide environment variables. This file will always be sourced and cannot be overridden. -
$ZDOTDIR/.zshenv
Used for setting user's environment variables. This file will always be sourced. -
/etc/zsh/zprofile
Used for executing commands at start, will be sourced when starting as a login shell. -
/etc/profile
This file should be sourced by all Bourne-compatible shells upon login: it sets up $PATH and other environment variables and application-specific (/etc/profile.d/*.sh
) settings upon login. -
$ZDOTDIR/.zprofile
Used for executing user's commands at start, will be sourced when starting as a login shell.-
$HOME/.profile
is not sourced by zsh.
-
-
/etc/zsh/zshrc
Used for setting interactive shell configuration and executing commands, will be sourced when starting as an interactive shell. -
$ZDOTDIR/.zshrc
Used for setting user's interactive shell configuration and executing commands, will be sourced when starting as an interactive shell. -
/etc/zsh/zlogin
Used for executing commands at ending of initial progress, will be sourced when starting as a login shell. -
$ZDOTDIR/.zlogin
Used for executing user's commands at ending of initial progress, will be sourced when starting as a login shell.
Solution 2
It looks as though the original value of PATH
comes from /etc/paths
.
Author by
OkBeat9
Updated on September 18, 2022Comments
-
OkBeat9 over 1 year
When I run
echo $PATH
, my output is:/usr/bin:/bin:/usr/sbin:/sbin
But in my
.zshrc
,$PATH
is commented out:# If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin:$PATH
So, where is my
PATH
variable defined at? I am usingoh-my-zsh
, not sure if it has any difference fromzsh
. -
Aaron Franke about 3 yearsOn macOS, it seems to be
/etc/zprofile
, but there is also/etc/paths
. -
tanutapi almost 3 yearsMy machine first loaded with /etc/paths.
-
aheigins over 2 yearsnone of these answers is where mines saving the exported paths too.. Really bizarre it's so opaque.
-
Admin almost 2 yearsIt looks like it will also source files inside
/etc/paths.d
.