How to find, open, and edit zshrc file on Mac
For many Mac users, Terminal is an application that sits in the Utilities folder and is never opened, either because they don’t need it or because they are slightly fearful of what it can do. For others, it’s the window into a world of exploration and customization via the command line. If you’re in the latter group, you’ll know that the default shell in Terminal is now zsh and that the key to customizing it is the zshrc file. If you’re not, you may be wondering what zsh and zshrc are and why they’re important. We’ll answer those questions and tell you how to find, open, and edit the zshrc file on your Mac.
What is zshrc?
Let’s start with the basics. macOS is based on UNIX. Strip away the GUI in macOS, and what you’re left with is a UNIX core. That means you can type commands and execute instructions using a command line interface. And the Mac has an application that allows you to do that — Terminal. In order for UNIX to understand the commands you type in Terminal, it needs an interpreter. Until macOS Catalina, that interpreter was bourne, also known as bash. Since Catalina, the interpreter is zsh. So, zsh is the interpreter or shell into which you type commands in Terminal (unless you change it to a different shell). One of the features of zsh is that it allows you to install plug-ins and themes. Zshrc is a configuration file that allows you to use those plug-ins and themes, often via a third-party tool like Oh My Zsh. Once created, it has a period before its name, meaning it’s a hidden file, so technically, its name is ‘.zshrc’
How to manage hidden files on Mac
Zshrc is just one of many files on your Mac you may not know about. There are hundreds, possibly thousands more. And while zshrc can be useful, most of these other files are not. They are what can be reasonably called junk files. They consist of files left over by applications you have removed, temporary files that were never deleted, old cache files, and language files for languages you don’t need. Removing these files could free up several gigabytes and prevent possible conflicts with other files in the future.
Getting rid of junk files manually is difficult and time-consuming. However, you don’t have to do it manually — CleanMyMac X’s System Junk module can do it for you. It scans your Mac looking for these junk files and, in just a few seconds, allows you to either delete them all with one click or review what it has found and choose what to delete yourself. You can download CleanMyMac X for free here. Then, click System Junk > Scan > Clean.
Where is zshrc on Mac?
By default, there is no user-specific zshrc file on your Mac. It doesn’t exist until either you create it or you install a tool like Oh My Zsh, which creates one for you. Once created, the zshrc file is stored in the root level of your home directory, often notated as ~/zshrc
There is a system-wide zshrc file located at /etc/zshrc. But how to open zshrc? In fact, it’s best not to open or edit that file, as anything you do to it will affect all users on your Mac. If you need to use a zshrc file, create one in your user home directory.
How to create a zshrc file on Mac
The easiest way to create a zshrc file on your Mac is to use the touch command in Terminal, like this.
- Go to Applications > Utilities and open Terminal.
- Type the following command:
- Press Return.
- The file has now been created. To see it, open a Finder window, navigate to your home directory, and press Command+Shift+period. You will see the hidden files, including the zshrc file you just created.
If you have a text editor you like to use in Terminal, you can also use that to create a zshrc file. So, for example, if you use nano in Terminal, the command would be:
Or you can use a GUI text editor like Text Edit. Just create a new file and save it at the root of your home directory with the name ‘.zshrc’
How to edit zshrc file on Mac
To edit a zshrc file in Terminal, you need to use a text editor. So, for example, if you use nano, to open the file, you would type:
nano ~/ .zshrc
You can then create a new line in the file with this command:
Then, use the PROMPT command to make changes to the zsh
prompt: PROMPT=‘ ’ with the variables you want to use to change the prompt between the quote marks.
If you want to change the theme of the zsh shell, you can use the following command:
When you’ve finished editing the zsh file, press Ctrl+O to confirm the changes and Ctrl+X to exit the text editor.
The zshrc file is a text file that can be used to customize the zsh file in Terminal. However, it doesn’t exist until you create it. Once you’ve created it, you can edit it to customize the zsh prompt, switch themes in zsh, and more.