Articles
Published · November 18, 2026

zshrc, zprofile, or zshenv? Which Startup File Runs When

zsh reads .zshenv for every shell, .zprofile for login shells, and .zshrc for interactive ones. Here is the exact order and where each kind of setting belongs.

Also in: Español中文हिन्दी

Short answer: .zshenv runs for every zsh, .zprofile runs for login shells, .zshrc runs for interactive shells, and .zlogin runs last for login shells. If you only remember one rule, put aliases and prompt settings in .zshrc, and put environment variables you need everywhere in .zshenv.

That's the whole map. Below you'll find the exact order, what each file is for, and where the lines you keep second-guessing, like PATH, belong.

Quick answer: the order zsh reads its files

According to the zsh manual, zsh reads commands in this order:

  1. /etc/zshenv, always. The manual says this cannot be overridden.
  2. $ZDOTDIR/.zshenv
  3. If the shell is a login shell: /etc/zprofile, then $ZDOTDIR/.zprofile
  4. If the shell is interactive: /etc/zshrc, then $ZDOTDIR/.zshrc
  5. If the shell is a login shell: /etc/zlogin, then $ZDOTDIR/.zlogin

When a login shell exits, $ZDOTDIR/.zlogout and then /etc/zlogout are read. The one exception is a shell that ends by exec'ing another process, which skips the logout files.

Here is the same thing as a table, for the files in your own folder:

| File | Read by | Typical contents | |---|---|---| | .zshenv | Every zsh | PATH, key environment variables | | .zprofile | Login shells, before .zshrc | One-time login setup | | .zshrc | Interactive shells | Aliases, functions, options, key bindings | | .zlogin | Login shells, after .zshrc | Terminal setup, external commands | | .zlogout | Login shells, on exit | Cleanup |

If ZDOTDIR is unset, zsh uses HOME instead, so on most machines these files live right in your home folder.

How it actually works: login, interactive, and neither

Two questions decide which files run. Is this a login shell, and is it interactive?

  • A login shell is the first shell of a session. It reads the profile and login files.
  • An interactive shell is one where you type commands at a prompt. It reads the rc files.
  • A shell can be both, either, or neither. A script you run with zsh script.sh is typically neither, so it reads only the zshenv files.

Whether your terminal app starts a login shell for each new window depends on the app and its settings. If a change in .zprofile seems ignored, the new window may simply not be a login shell.

.zshenv: every shell, so keep it small

The zsh introduction says .zshenv is sourced on all invocations of the shell, unless the -f option is set. It should hold the command search path and other important environment variables. It should not contain commands that produce output or assume the shell is attached to a terminal.

That makes it a good home for a small, quiet line like this:

export PATH="$HOME/bin:$PATH"

The manual adds a warning about the global version: because /etc/zshenv runs for every instance of zsh, it should be kept as small as possible. The same logic applies to your own .zshenv. Anything slow or chatty in there runs for scripts and tools too, not just when you're at a prompt.

If you want a refresher on how plain-text variable files are written, see .env file syntax: quoting, comments, and multiline values. For how scripts pick their interpreter, see the shebang line.

.zprofile and .zlogin: login shells only

.zprofile is read for login shells, before .zshrc. The zsh introduction describes it as similar to .zlogin, except that it is sourced before .zshrc, and says it is meant as an alternative to .zlogin for ksh fans. The two are not intended to be used together, although you can.

The introduction also says .zlogin should not change the shell environment at all. Use it to set the terminal type or run external commands, not for aliases, options, or variables. For most people the practical advice is simple: pick .zprofile for login-only setup, and leave .zlogin empty.

.zshrc: where most of your changes go

.zshrc is sourced in interactive shells. The introduction says it should set up aliases, functions, options, key bindings, and the like. It is the file most people edit, because it holds everything you want to feel at the prompt:

alias gs="git status"
setopt autocd

Because it only runs for interactive shells, a typo here won't break your scripts. A slow .zshrc does delay every new prompt, though.

When to use it (and when to skip it)

A quick cheat sheet:

  • Variable every program should see, such as `PATH`: .zshenv
  • Alias, function, option, or key binding: .zshrc
  • Something that should happen once per login: .zprofile
  • Anything that prints text: not .zshenv
  • Moving all of these to another folder: set ZDOTDIR

Skip the global /etc files unless you are managing a whole machine. Edit your own files in your home folder, and keep a copy under version control. We cover that in keeping your dotfiles in a Git repository.

One more detail from the manual: any of these files can be pre-compiled with zcompile. If a .zwc file exists and is newer than the original, zsh uses the compiled file. If an edit seems to have no effect, check for a stale .zwc next to the file.

How Carets fits in

These startup files are plain text, and you'll edit them often: a new alias here, a PATH tweak there. Carets is a native notes and code editor for iPhone, iPad, and Mac that keeps Markdown, plain text, and code in one place, with syntax highlighting for code and config files. You can keep a short note of what each of your startup files does, alongside the snippets you reuse, organized into files, projects, and tags. Your files stay plain text, so they stay portable.

Get Carets on the App Store for iPhone, iPad, and Mac.

Frequently Asked Questions

Which file runs first in zsh?

/etc/zshenv runs first, then $ZDOTDIR/.zshenv. Every zsh reads both, per the zsh manual, unless it is started without startup files.

Do I need both .zprofile and .zlogin?

No. The zsh introduction describes .zprofile as an alternative to .zlogin and says the two are not intended to be used together. Most people use only .zprofile.

Where should I put PATH changes?

.zshenv is the file the zsh introduction points to for the command search path and other important environment variables. Keep the line quiet: no output, and nothing that assumes a terminal.

What does ZDOTDIR do?

It tells zsh where to look for your user startup files. If it is unset, zsh uses HOME instead.