Where is the .zshrc file on Mac?
I’m using iTerm and wanted to customize the look of my terminal window using Oh My ZSH!. And according to the documentation I need to change the ~/.zshrc
file and add a ZSH_THEME
value:
Once you find a theme that you want to use, you will need to edit the
~/.zshrc
file. You'll see an environment variable (all caps) in there that looks like:ZSH_THEME="robbyrussell"
The problem is I don’t know where to find the ~/.zshrc
file.
The ~/.zshrc
doesn’t exist by default in macOS so you need to create it. The ~/
translates to your user’s home directory and the .zshrc
is the ZSH configuration file itself.
So open up a Terminal — or iTerm — window and create that file like this; I am using nano
as a text editor but feel free to use whatever text editor you feel comfortable with:
nano ~/.zshrc
And then set the ZSH_THEME
value to whatever value you want to use like this:
ZSH_THEME="robbyrussell"
Now to save the file in nano
, hit ctrl+X. When it prompts:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?
Type “Y” and then you will get a new prompt which looks something like this; note the path /Users/giacomo/
will match your local user’s path:
File Name to Write: /Users/giacomo/.zshrc
Now hit return and the file will be saved and you will now be back to the command line prompt in the Terminal. If you now exit from the Terminal and then open a new window, the ~/.zshrc
settings should now be loaded in.
The .zshrc
file is not present by default in macOS Catalina, we need to create it.
Steps for creation:
- Open Terminal
- Type
touch ~/.zshrc
to create the respective file. (touch
command will create the.zshrc
in your current directory but it will be hidden) - Hit Return
To view/open ~/.zshrc
you can do either of two things:
- Open Finder > Press Cmd+Shift+.
Or:
- Open Terminal > and type:
open ~/.zshrc
I am using macOS High Sierra, MacBook Pro.
After I installed a Theme, I also needed to change the ZSH_THEME
.
For me, ~/.zshrc
was already present in my Home directory, but it was Hidden.
I used Cmd + Shift + . to show the hidden files in Finder, then opened the ~/.zshrc
files with my editor. Updated it and saved it. It worked fine.
"oh-my-zsh" now creates ~/.zshrc
automatically now. Immediately afterwards on my OSX Catalina Macbook I executed:
vi ~/.zshrc
And the file was already there; no manual intervention to create it was required on my part.
And directive ZSH_THEME
you require was already present:
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
- Opening iTerm
- You write
cd
and immediately appear in your account directory to check, writepwd
(it is very useful to know this command to understand the directory tree). - Now write
ls -la
- will display a list of all files (-la will display along with hidden files). - Find the .zshrc file. You can read the contents with
cat ~ / .zshrc
. Edit:vim ~ / .zshrc
. To edit in vim press thei
button, to save the changes -esc +: qw
. - Done
Useful Links: [Commands in Terminal] (https://www.makeuseof.com/tag/mac-terminal-commands-cheat-sheet/) [Getting started with vim] (https://opensource.com/article/19/3/getting-started-vim)