Home > How to Tips

[Solved] ZSHRC File: Located & Create & Customize

Updated on Monday, April 29, 2024

iBoysoft author Eudora Liu

Written by

Eudora Liu
Professional tech editor

Approved by

Jessica Shee

English Français Deutsch やまと Español Português

How to Create ZSHRC File On Mac

Summary: .zshrc file is a configuration file of ZSH and does not exist in macOS, so you need to create a new one manually. This post tells you how to create it on a Mac and where to locate it on your Mac.

How to Create ZSHRC File On Mac

Z shell, also called zsh, is an extended version of Bourne shell that includes myriad new features, accessibility to themes, and support for plugins. If you are a regular Terminal user, you may notice that zsh is now the default shell in Terminal.

As the upgrade of Bash, zsh has plugin and theme support, which allows zsh to include different plugin frameworks. It also includes the spelling connection, allowing zsh to fix minor typing mistakes.

When you launch the zsh shell, you won't find the zshrc file used to configure the zsh shell, so you need to manually create one in your home directory for zsh to access. In this post, we explore what the zshrc file is, where to find it, and how to create it on Mac. Let's get it.

I would appreciate it if you'd like to share this post.

 

What is a zshrc file?

A .zshrc file is a Z-Shell or ZSH resource file located on any MacOS wherein the user has created a .zshrc file (since these files are not created by the shell by default). Zsh shell (or prompt) uses the settings contained in this file. The file is more or less a script that runs whenever you start the ZSH shell.

The main function of the file is to set the environment for interactive shells. The usage and role of zshrc are similar to that of the bash_profile file compared to the Bash shell.

Create a zshrc file

Well, because ~/.zshrc, including the .zshrc file, does not exist in macOS by default, you need to create one. In ~/.zshrc, '~/' indicates the user's home directory and the .zshrc indicates the ZSH file configuration itself.

You need to Terminal to create a .zshrc file. Here are the steps.

Step 1: Go to Launchpad > Other > Terminal and double-click it to open. (Or you can go to Finder > Applications > Terminal and double-click it to open.)

Step 2: Type in the following command and then press Enter to run.

nono ~/.zshrc

Create a zshrc file

Step 3: After that, set the ZSH_Theme value.

Step 4: Press Control + X to save the changes.

Step 5: Press Y when you see the prompt 'Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES)?'

Step 6: Press Enter and the new .zshrc file will be saved.

Once finished, exit the terminal and open a new window and you should see the ~/.zshrc settings loaded onto it.

How to customize a zshrc file?

The default zsh prompt carries information like the username, machine name, and location starting in the user's home directory. These details are stored in the zsh shell's system file at the /etc/zshrc location. To make any change to the default zsh prompt, you will have to add related values for the prompt to appear differently than the default.

  1. Open Terminal, type the following command and hit Enter. 
    nano ~/.zshrc
  2. Type in textPROMPT='...' to add a new line.
  3. Type in PROMPT='%n~$' values in the .zshrc profile
  4. Hit Ctrl + O to confirm making those changes to the file, and then hit Ctrl + X to exit the nano editor.

Where is a zshrc file located?

After you create a .zshrc file, it's easy to find it on your Mac.

Step 1: Go to Launchpad > Other > Terminal and double-click it to open. (Or you can go to Finder > Applications > Terminal and double-click it to open.)

Step 2: Type in 'cd ~' to move to your user folder/

Step 3: Type in 'ls -a,' which will show you all the files available.

Step 4: From amongst these files, look for the .zshrc file, which should be listed amongst the rest of the files that are displayed upon typing ls -a.

Step 5: Type the following command to view the content of the file.

% cat ~/.zshrc

If you haven't created the file and are looking for it, you will get the error 'cat: /Users/code2care/.zshrc: No such file or directory.'