The .zshrc file is a hidden configuration file used by the Zsh shell on macOS to store user preferences, environment variables, and shell customizations.
Located in your home directory, it is essential for customizing your Terminal experience. This guide walks you through understanding the file, locating it, and safely opening, editing, saving, and exiting it.
What is the .zshrc file on Mac
The .zshrc file is a user-specific configuration script used by the Z shell (Zsh), which has been the default shell on macOS since Catalina (10.15). It runs automatically every time you start a new Terminal session, allowing you to define how your shell behaves and appears.
Unlike system-wide settings, the .zshrc file gives individual users full control over their shell environment. You can use it to:
- Set environment variables (like PATH or EDITOR).
- Create aliases (shortcuts for long commands).
- Load plugins or frameworks (like Oh My Zsh or zinit).
- Customize prompts, shell themes, and command behaviors.
- Configure autocompletion and syntax highlighting.
Share to let more people know about the .zshrc file!
Where is the .zshrc file on a Mac
The .zshrc file is located in your Mac's home directory, but it is hidden by default because its name starts with a dot (.), which is a Unix convention for hidden files.
You can try the following two methods to find the .zshrc file.
Option 1. Use Terminal
You can quickly check if the file exists by opening Terminal and typing:
ls -a ~
This lists all files in your home directory, including hidden ones. You can look for .zshrc in the list.
Option 2. Use Finder (Graphical Interface)
Finder is an alternative way to find the .zshrc file, but it is a little bit complicated.
- Open Finder.
- Press Command + Shift + . to toggle hidden files.
- Go to your home folder (/Users/your-username/).
- Look for a file named .zshrc.
If you don't see the file, it might not exist yet. In that case, you can learn how to create a .zshrc file on Mac.
How to open, save, and exit the .zshrc file on Mac
How to open the .zshrc file
There are multiple ways to open the .zshrc file on macOS, and you can choose one that suits you. Type the Terminal command listed below to open the .zshrc file.
Using Nano
nano ~/.zshrc
This will open the .zshrc file in the Nano text editor right in the Terminal.
Using Vim
vim ~/.zshrc
Vim offers more control but has a steeper learning curve.
Using Visual Studio Code
code ~/.zshrc
If you have VS Code installed and the code command set up, this will launch the file in a GUI editor.
Using TextEdit
open -a TextEdit ~/.zshrc
This opens .zshrc using macOS's built-in TextEdit app.
How to save the .zshrc file
In nano, you can press Control + O (the letter O, not zero), and press Enter to confirm saving. Then press Control + X to exit
In vim, you can first press Esc. Type :w and press Enter to save. Then type :q and press Enter to quit. (Or use :wq to do both at once)
In VS Code or TextEdit, you can press Command + S to save, then close the window
Exit without saving (If needed)
In nano, press Control + X. When prompted to save, press N (No).
In vim, press Esc. Type :q! and press Enter (quit without saving).
In GUI Editors, just close the window and click “Don't Save” when prompted.
Share this article with your friends if you find it useful!