I just upgraded to macOS Catalina and the new shell is ZSH. So, since it's a fresh start, I'm trying to set up my shell environment with aliases, functions, etc. like I had in bash. I'm trying to figure out what goes where, when I ran across this in the documentation

Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

The confusing bits...

  • If it's a login shell it reads from /etc/zprofile and then $ZDOTDIR/.zprofile
  • Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

If I SSH to my Mac, it's a login shell. So since I need to configure that, which files do I need to (or should) modify? I guess to help answer that question it probably would help to understand the difference between .zprofile and .zlogin So, any guidance here would be awesome.


The *profile files and the *login files are read under the same conditions: if and only if the shell is a login shell (and not invoked with an option such as no_rcs). The manual lists them separately because they're invoked in a different order relative to the *rc files.

The name *profile comes from sh, the Bourne shell (which ksh, bash, dash and others are mostly reimplementations of with extra features). The name *login comes from csh. Zsh is more sh-like but has features from both, so I guess that's why it supports both names.

Often it doesn't matter whether you use *profile or *login. But *profile files have the advantage that they're read before *rc, so if you have *rc content that depends on settings from *profile (for example, if your .zshrc calls a program which is in a directory that .zprofile adds to $PATH), you need to use *profile and not *login.

So put login-time configuration (usually mostly environment variables) in ~/.profile, and interactive configuration (prompt, completion, key bindings, aliases, …) in ~/.zshrc. You'll rarely need the other startup files.

  • 1
    That last sentence in the first paragraph is what should be in the ZSH documentation!
    – Allan
    Apr 14 '20 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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