How to manage zsh startup files with correct settings

Overview

The shell program uses a collection of startup files that helps users to create an environment. Each file has a specific use and may affect login and interactive environments differently. If an equivalent file exists in our home directory, it may override the global settings. This makes it more important to hold the correct information in each file.

The required list of startup files, along with the details of the information, is given below:

The .zshenv file

The .zshenv file is always sourced, so it should set environment variables that need to be updated frequently. It often contains exported variables that should be available to other programs, For example, $PATH and $EDITOR are often set in .zshenv. This file is read when zsh is launched to run a single command as well. The commands which run once should be updated on each new shell and must be declared in this file.

The .zshrc file

The .zshrc file is for interactive shell configuration. We can set the following options for the interactive shell in this file:

  • Command completion, correction, and suggestion
  • Highlighting
  • Aliases
  • Key bindings
  • Commands history management
  • Set any variables that are only used in the interactive shell $LS_COLORS.

Note: Non-Interactive shell is used to execute a script for once whereas an Interactive shell is invoked whenever we open a new terminal.

The .zlogin file

The .zlogin file is sourced at the start of a login shell. This file is sourced after .zshrc file, and it helps to maintain the commands that are to be run when the shell is fully set up.

The .zprofile file

The .zprofile file is basically the same as .zlogin except that it's sourced directly before .zshrc  instead of directly after it.

Note: According to the zsh documentation, " The .zprofile is meant as an alternative to.zlogin. The two are not intended to be used together, although this could certainly be done if desired."

It is advised to have command in .zprofile file, which may take some time to complete, or variables that are not updated frequently.

The .zlogout file

The .zlogout file is used to clear and reset the terminal, so it can be used to release all the resources acquired at the time of login.

Free Resources

Attributions:
  1. undefined by undefined
Copyright ©2025 Educative, Inc. All rights reserved