Zsh Shell

The Zsh shell is available for Linux but also the current default for macOS. The official documentation is available at ZSH - THE Z SHELL.

When logging into a interactive Zsh shell the following are executed in this order:

  1. .zshenv - always used and often contains environment variables, but note my comment on path below
  2. .zprofile - same as .zlogin really
  3. .zshrc - for interactive shell configuration

These files and their execution order is described at Moving to zsh, part 2: Configuration Files – Scripting OS X if you want more details. The path can be modified via an array and you can easily prevent duplicates, see A User's Guide to the Z-Shell, however, one thing I have found is that between the execution of .zshenv and .zprofile the path order is changed. This is explained in How $PATH is Constructed on macOS and can be summarised as follows:

  • Use .zshenv to define environment variables, like JAVA_HOME, you can add to PATH but it will not retain the order
  • Use .zshrc for overriding PATH order, so to set precedence for brew installed things for example
  • Generate "stuff" can do in .zprofile or .zlogin if you like to keep things separate

There is a handy introduction to zsh at Zsh: the sheet | 111, which you might find useful.