Why are there so many of them?
zsh reads up to four config files at startup. Each has a different purpose. Putting the right line in the wrong file is the most common "my env doesn't load" bug.
The four zsh files
~/.zshenv— runs for every zsh invocation, including non-interactive scripts. Use sparingly.~/.zprofile— login shells only (the first shell of a session). Set$PATHhere. Homebrew shellenv lives here.~/.zshrc— interactive shells. Aliases, prompts, plugins, completion. Most of your config goes here.~/.zlogin— login shells, after .zshrc. Rarely used.
The bash equivalents
~/.bash_profile— login shells.~/.bashrc— interactive non-login shells.- Old hack: source one from the other so you only edit
.bashrc.
Login vs interactive (preview)
Login shell = first shell of a session (Terminal opens, ssh, su -). Interactive = you can type at a prompt. Most macOS Terminal sessions are both; ssh sessions are too. Subshells (bash from inside zsh) are interactive but not login. Next lesson covers the table.
Where to put what
- PATH and locale → .zprofile (so non-interactive scripts via launchd see them too).
- Aliases, functions, prompt → .zshrc.
- Variables you want every script to see → .zshenv (rare).
Reload after editing
source ~/.zshrc or exec zsh reloads. The second is cleaner — it replaces the current shell with a fresh one and preserves your terminal window.