Where the .zshrc File is Located on Mac

Nov 18, 2021 - Leave a Comment

Where the zshrc file is located on Mac

Wondering where the .zshrc file is located on a Mac? If you’re a Mac command line user who is interested in using and customizing the zsh shell, or using something like Oh My Zsh, you may be curious to know what and where the .zshrc file is located, and how to access it so that you can customize your shell.


If you’re a regular Terminal user, you probably noticed that zsh is now the default shell in MacOS Terminal app (and yes you can change the shell to bash, tcsh, ksh, zsh, etc if you want to, but we’re focusing on zsh, the default).

By default, the .zshrc file does not exist for a standard user, even if you launch the zsh shell. This may come as some surprise, but since the .zshrc file is used to configure the zsh shell, you’ll need to manually create one in your home directory for zsh to access. There’s also a system-level zshrc file, but that is less commonly modified by users.

Do note that if you install Oh My Zsh, a .zshrc file will be created automatically for you.

Where is the .zshrc file on a Mac?

The .zshrc file will be located in the users home directory, or ~/, and this user .zshrc file is where you’d place customizations to the z shell.

Thus, the user .zshrc file will be in the following path location:
~/.zshrc

If you have not yet manually created a .zshrc file, the file will not exist by default.

You can create one with:

touch ~/.zshrc

Or by launching a text editor to create .zshrc, like nano:

nano ~/.zsrch

You can then place whatever you’d like to in the .zshrc file, for example, any aliases, path modifications, export customizations, ZSH_THEME configs, etc.

Changes will take effect when you reload zsh profile or launch a new terminal window.

Where is the universal system-wide zshrc file?

While the user customizable .zshrc file resides in the users home directory, there is also a system level zshrc file.

The system zshrc file is located at the following path in macOS:

/etc/zshrc

Any modification made to /etc/zshrc will apply to the zsh shell for all users, regardless of whether or not they have an individual user level .zshrc file in their home directory.

Generally speaking, it is not recommended to modify /etc/zshrc, and instead all user level notifications to zsh should be made in the user .zshrc file found in the root of their home directory.

What about setting environment variables with zsh?

You can set environmental variables for zsh at:

~/.zshenv

You can modify that file with any command line text editor, like nano, vim, emacs.

For example, you could add:

JAVA_HOME=$(/usr/libexec/java_home)

SHELL_SESSION_HISTFILE=/Users/o/.zsh_sessions/zshHistory.history

You can learn more about setting environment variables here.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site