Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The title says it all. I'm looking for guidelines on what one should and should not include in the various startup files for zsh.

I understand the order of sourcing of these files, and the conditions under which they are sourced, but it is still not clear to me what should go in each.

share|improve this question
up vote 51 down vote accepted

Here is a non-exclusive list of what each file tends to contain:

  • Since .zshenv is always sourced, it often contains exported variables that should be available to other programs. For example, $PATH, $EDITOR, and $PAGER are often set in .zshenv. Also, you can set $ZDOTDIR in .zshenv to specify an alternative location for the rest of your zsh configuration.
  • .zshrc is for interactive shell configuration. You set options for the interactive shell there with the setopt and unsetopt commands. You can also load shell modules, set your history options, change your prompt, set up zle and completion, et cetera. You also set any variables that are only used in the interactive shell (e.g. $LS_COLORS).
  • .zlogin is sourced on the start of a login shell. This file is often used to start X using startx. Some systems start X on boot, so this file is not always very useful.
  • .zprofile is basically the same as .zlogin except that it's sourced directly before .zshrc is sourced instead of directly after it. According to the zsh documentation, ".zprofile is meant as an alternative to `.zlogin' for ksh fans; the two are not intended to be used together, although this could certainly be done if desired."
  • .zlogout is sometimes used to clear and reset the terminal.

You should go through the configuration files of random Github users to get a better idea of what each file should contain.

share|improve this answer
Just as a point of clarity, .zlogin is sourced after .zshrc (see man zshall for details). – Aaron Mar 31 '15 at 16:09
Be aware when setting $PATH in .zshenv, various other files all are sourced after this file that will override this value. See zsh.org/mla/users/2003/msg00600.html. – Beau Barker Oct 6 '15 at 0:19
Where should $LANG and $LC_ALL go? – Lenar Hoyt Nov 24 '15 at 19:41
Just for my own notes / confirmation and to help anybody else, the ultimate order is .zshenv → [.zprofile if login] → [.zshrc if interactive] → [.zlogin if login] → [.zlogout sometimes]. – Gabriel L. May 18 at 20:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.