Home > How to Tips

How to Create ZSHRC File On Mac

Updated on Tuesday, December 3, 2024

Written by

Eudora Liu

Approved by

Jessica Shee

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

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.

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.

The quickest way to create a new file on Mac

By default, macOS's context menu includes the "New Folder" option, but lacks a "New File" option, making it less convenient to create new files directly.

iBoysoft MagicMenu addresses this by adding a "New File" shortcut to the context menu, enabling users to create various file types like doc, docx, xls, xlsx, txt, pdf, ppt, Keynote, Pages, Markdown, and Numbers with a simple right-click on the desktop or in a folder. This eliminates the need to open applications to create new files.

Additionally, iBoysoft MagicMenu allows users to import a blank or pre-edited template file from a local folder as a shortcut if the desired file type isn't listed by default. If you need, have a try~

Reddit discussion on how to create .zshrc file on Mac

Many users need to create .zshrc files in life and work, so they want to find the easiest way. 

The OP from Reddit also asks us for help to create .zshrc file on Mac, many of them give the soulutions to create in Terminal.

Meanwhile, some of them also want to edit and locate the zshrc files on Mac. How to achieve these all? Continue reading and find the answers.

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.

  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.)
  2. Type in the following command nono ~/.zshrc and then press Enter to run.
  3. After that, set the ZSH_Theme value.
  4. Press Control + X to save the changes.
  5. Press Y when you see the prompt 'Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES)?'
  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.' 

Please share this post to help more people~