Skip to content

Instantly share code, notes, and snippets.

@meg-gutshall
Last active January 14, 2026 01:11
Show Gist options
  • Select an option

  • Save meg-gutshall/9613a04530ca72df4df150e5c37652ce to your computer and use it in GitHub Desktop.

Select an option

Save meg-gutshall/9613a04530ca72df4df150e5c37652ce to your computer and use it in GitHub Desktop.

Z Shell Overview

~/.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.

~/.zshenv (Z Shell Environment)

  • 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).

~/.zprofile (Z Shell Profile)

  • When: Only for login shells (e.g., first terminal window, SSH login).
  • What: Commands that should run once per login session, like setting the terminal title or loading specific modules.
  • Why: Variables set here (like $PATH) are inherited by all subsequent shells, unlike ~/.zshrc settings which only affect interactive sessions.

~/.zshrc (Z Shell Run Commands)

  • When: Every interactive shell (new terminal, new subshell).
  • What: Aliases, functions, key bindings, prompt customization (PS1), command completion, and other interactive features.
  • Why: It's the primary file for customizing your day-to-day interactive experience.

Loading Order (Login Interactive Shell)

  1. ~/.zshenv (sets global environment variables).
  2. ~/.zprofile (sets login-specific environment/tasks).
  3. ~/.zshrc (sets interactive settings, overrides profile settings).
  4. ~/.zlogin (runs after profile/rc for final login tasks).

References

*AI responses may include mistakes.

  1. https://gist.github.com/pbrisbin/45654dc74787c18e858c
  2. https://zerotohero.dev/tips/zshell-startup-files/
  3. https://unix.stackexchange.com/questions/71253/what-should-shouldnt-go-in-zshenv-zshrc-zlogin-zprofile-zlogout
  4. https://www.reddit.com/r/zsh/comments/kwmrf4/help_me_understand_best_practices_re/
  5. https://zsh.sourceforge.io/Intro/intro_3.html
  6. https://stackoverflow.com/questions/73416959/why-vs-code-on-macos-suggests-add-path-to-zprofile-instead-of-zshrc
  7. https://www.reddit.com/r/zsh/comments/1ezfy7k/what_cant_be_dumped_into_zprofile/
  8. https://community.cisco.com/t5/devnet-general-knowledge-base/developer-basics-creating-aliases-with-bashrc-and-zshrc/ta-p/4672529
  9. https://mac.install.guide/terminal/zshrc-zprofile
  10. https://www.freecodecamp.org/news/how-do-zsh-configuration-files-work/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment