In zsh on mac OS, where is the source of $PATH? I cannot find it in .zshrc

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 using oh-my-zsh, not sure if it has any difference from zsh.


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.

source : wiki.archlinux.org

Solution 2:

It looks as though the original value of PATH comes from /etc/paths.