~/.zshenv runs first on all shell sessions (login/non-login, interactive/non-interactive) for universal environment variables like PATH; ~/.zprofile runs for login shells only (like a fresh terminal window) for login-specific settings (PATH, terminal title); and ~/.zshrc runs for interactive shells (every time you open a new terminal/subshell) for aliases, functions, prompts, and other interactive customizations. Use ~/.zshenv for global envs, ~/.zprofile for login setups, and ~/.zshrc for daily interactive tweaks.
- When: Every single time a Zsh shell starts (login, non-login, interactive, non-interactive).
- What: Essential, fundamental environment variables that must be set for any shell invocation, like
$PATH. - Don't put: Commands that produce output or rely on an interactive terminal (tty).