Whta is .zshrc file on Mac?
Asenqua Tech is reader-supported. When you buy through links on our site, we may earn an affiliate commission.
ZSH Meaning
ZSH or the Z Shell is an extended version of the Bourne Shell (sh), with the incorporation of myriad new features, accessibility to themes and support for plugins. If you had been using Bash on your MacOS so far, switching to ZSH should be a breeze since it is based on the same shell as Bash.
Coming off as an upgrade to Bash, ZSH’s major feature highlights are:
- Plugin and theme support, which now allows ZSH to include different plugin frameworks.
- Spelling correction which allows ZSH to fix minor mistakes while typing. ZSH also has approximate completion.
- Automatic cd, which allows you to just type the name of the directory.
- Recursive path expansion. An example of recursive path expansion in ZSH would be: “/u/lo/b” expands to “/usr/local/bin”
What is a .zshrc file?
A .zshrc file is a Z-Shell or ZSH resource file located on any MacOS wherein the user has createda .zshrc file (since these files are not created by the shell by default). 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. By this, we mean,all paths you have set in ZSH, the initializations you want performed at the start-up of the shell, etc., are put in ~/.zshrc. The ~ is a file located in the current user’s home directory, whereas the .zshrc is the file called .zshrc, itself.
How to create a .zshrc file?
Since ~/.zshrc (includes the .zshrc file) does not exist by default in macOS, you will need to create one. In ~/.zshrc, ~/ simply refers to your user’s home directory and the .zshrc is the ZSH file configuration itself.
To create a .zshrc file, you will need to open up a Terminal or iTerm window and create a file using the steps mentioned below. You can use whichever text editor you feel comfortable with; we used nano for the procedure.
Once you have created a window in the Terminal, use the command:
nano ~/.zshrc
Now, set the ZSH_Theme value according to your liking, for example, ZSH_THEME=”yoodleyblog”
To save these changes made, hit CTRL + X, which in turn will prompt the following:
Save modified buffer (ANSWERING “No” WILL DESTROY CHANGES)?
Type ‘Y’ in the prompt and you will receive a new prompt. Once that happens, note the file path that shall match with your local user’s path.
Hit the return button and your file will now be saved. This will also take you back to the command line prompt in the Terminal which you can exit since the changes should be loaded by now.
Exit the terminal and open a new window and you should see the ~/.zshrc settings loaded onto it.
Where is the .zshrc file located on Mac?
Given that you have already created a .zshrc file in your ZSH shell, locating it is an easy task.
Follow the steps below to locate your .zshrc file on your MacOS:
- Open Spotlight Search
- Type Terminal or an equivalent of the same and open it.
- Now, type cd ~. Typing this command will move to your user folder/
- Next, type ls -a, which will show you all the files available.
- 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.
- To view the content of the file, type the following command:
% 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”.
- In this case, follow the steps mentioned in the segment above to create a .zshrc file.
How to add $PATH in a .zshrc file?
- Open Terminal on your MacOS
- In the Terminal, type zsh followed by the ‘enter’ button to enter the ZSH shell if you are not on the ZSH shell already.
- Next, you are required to add your $PATH variable details. An example for the same would be: export PATH=”$PATH:/opt/homebrew/bin/”
- To save the file and exit the text editor (considering it is Nano), press CTRL + X, followed by ‘Y’.
- Next, you need to type in the command source ~/.zshrc in order for changes to be applied in your .zshrc file.
Different files in ZSH and their operative chronology
If you have recently switched to a newer Macbok, you already know that your ~/.bash_profile will be completely replaced by the better ~/.zprofile with an added ~/.zshrc file.
When you look at the ZSH documentation , you will come across a number of files that are located in the home directory that goes as . $HOME or ~/. These files are:
- .zprofile – the login shell for ZSH
- .zshenv – the environment variables in ZSH
- .zshrc – the interactive shell in ZSH
- .zlogin – the login shell (the same as .zprofile).
- .zlogout – when the shell exits.
The question is how should you configure these files in the right chronology and what Startup/Shutdown files should be used when setting up the ZSH shell environment?
Let’s look at the operative configuration of these file and what these files mean in ZSH on MacOS:
.zprofile and .zlogin
.zlogin and .zprofile set the environment for login shells, and are practically more or less the same thing. The only difference that sets them apart is the time when they get loaded.
.zlogin is a derivative of CSH’s login, while .zprofile is based on the Bash’s .bash_profile. Which one should you use? Although you can use either of them, we are of the opinion that since Bash used to be the default shell for everything until the coming of Mojave, it is ideal to stick with .zprofile.
.zshrc
.zshrc file is the file that gets loaded right after .zprofile. Setting the environment for interactive shells, .zshrc is typically a path where you work on parameters such as $PATH, $PROMPT, aliases, and functions; in gist, “set it and forget it” parameters and functions that you would like to have in both login and interactive shells.
.zshenv (Optional)
.zshenv is an optional file where you set environment variables. It is read first and read every time file and is geared more towards advanced users. This is why we call it optional. If having a $PATH, $PAGER, or $EDITOR variables are important for scripting that get called by launchd, .zshenv is an important file, otherwise you would be fine overlooking it.
Since the variables mentioned above run under non-interactive shells, anything with .zprofile or .zshrc won’t be loaded without .zshenv. One workaround for not using .zshenv would be to set your $PATH variables in the script manually. One added advantage of doing this is portability.
.zlogout (Optional)
Although .zlogout is optional, it is a very useful file. The file is read when you log out of a session and works great for cleaning up, such as resetting the Terminal Window Title when you leave.
Order of Operations
Below we have enlisted the order of operation or the order in which these files are read in the ZSH shell.
Note: These files are first read from the system-wide file and then followed by reading from the files present in your home directory.
.zshenv → .zprofile → .zshrc → .zlogin → .zlogout
How to fix “zsh: command not found”?
If you are facing the “zsh: command not found” error in ZSH, there are multiple ways to fix it depending on what really caused the error. Thus, let us first understand the multiple reasons that could be the source to the occurence of the error, before we get to the solutions.
Why does the error occur?
More than getting an easy fix to the error, it is important to know what causes the error. The most common reasons why you are facing “zsh: command not found” error in ZSH on your Mac are:
- the command syntax was entered incorrectly, as in misspelled or invalid
- the users $PATH is incomplete, or $PATH has been erroneously set, reset, or cleared – this is the most common reason to see a ‘command not found’ message
- the command you are attempting to run is not installed
- the command was deleted, or, worse, the system directory was deleted or modified.
Fixing “zsh: command not found”:
- “Command not found” because command isn’t installed? Use HomeBrew
“Command not found” error is very common and it basically occurs because the command is not installed in the MacOS. Homebrew packages come with wget, htop and other useful Unix commands, so it is recommended to install Homebrew to fix this error. You can get easy access to command line utilities if you spend time in the Terminal.
- “Command not found” because a system directory is missing? Restore the missing system files
Deleting a system file from MacOS is quite a common and frequent mistake that happens with the users experimenting with the RM/SRM commands or a Wildcard.
To fix this error a user just needs to restore from a backup that they must have created before performing an experiment, or else they have to reinstall the system software itself.
- Executed an invalid command
For example:
% cls
zsh: command not found: cls
In the above example, cls is used but it is not a command that is used to clear the screen in Linux/ Mac OS based operating systems. Hence you get the error for an invalid command.
- Executed command is misspelled,
For example:
% gerp ‘myfile.txt’
zsh: command not found: gerp
In the above example command grep is misspelled as gerp which causes the error.
- The command package is installed and not set in the $PATH environment.
For example:
% mvn
zsh: command not found: mvn
In the above example the user gets the error even if the external command package is installed, because it is not set in the $PATH environment variable. Hence it is necessary to set an external command package in the $PATH environment variable to fix the error.
- The command path is not set in the .zshrc file.
One needs to set the $PATH variable permanently, in the .zshrc file, otherwise the $PATH variable will be available only till the Terminal session.
How to customise ZSH with open source tools?
One of the greatest perks offered by ZSH over Bash is the customisation support. Below we have enlisted the steps you can use to customise ZSH with open source tools:
- Step 1: Install Oh My Zsh
Oh My Zsh, an open source community driven framework for managing Zsh configuration, it comes with a number of helpful functions, plugins and themes.
You can install it with the following:
$ sh -c “$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)”
- Step 2: Install Powerlevel10k fonts
Powerlevel10k is a MIT-Licensed Zsh theme; in order to install Powerlevel10k, you need to install custom fonts from your terminal.
To download the Custom Fonts, go to Powerlevel10 GitHub and search for fonts in the README section. The process of installing custom fonts varies for different operating system links Linux, Windows and Mac OS. Mostly the installation process is just a matter of a few simple clicks.
- Step 3: Install the Powerlevel10k theme
Run the following command:
” git clone –depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ” to install Powerlevel10k theme.
Once it’s done, use a text editor like Vim to open a ~/.zshrc configuration file and set a line ZSH_THEME=”powerlevel10k/powerlevel10k .
Finally, save the file.
- Step 4: Finalize your Powerlevel10k setup
Now open a new terminal; if you don’t see the Powerlevel10k configuration wizard just run p10k configure to get the configuration wizard.
The icons and symbols will show correctly if you have followed all the steps correctly. Now you just need to change the default font to MeslowLG NF.
FAQs
Q. How to create and delete files in ZSH?
Files and folders with specific name and type can be created, and deleted in the Terminal.
touch FileName.type creates an empty new file with specified name and type.
mkdir FolderName it will create a new folder with the name given in command.
rm FileName.type this command will delete the file referred to the current folder.
rmdir FolderName it will revive the empty folder from the current directory.
Remember that the deleted files and folder cannot be recovered later, so be careful before deleting something. Deleting a wrong file or folder can cause serious damage to your system.
rm -r FolderName command can remove a folder with all the files and folders it contains.
Q. How to copy and move files and folders in ZSH?
Copying and moving files and folders in ZSH requires a source path and a target path.
cp /project/index.html /new-project/ command will copy the “index.html” folder from the source path “project” to the target path “new-project”.
cp -r /project/ /new-project/ command will copy the whole “project” folder along with the folders and files in it to the new folder “new-project”.
mv /project/index.html /new-project/ command will directly move the “index.html” file to the “new-project” folder.
mv /project/index.html /project/index2.html command will rename the “index.html” file.
Q. How does basic navigation in ZSH work?
pwd command prints our current path.
ls command shows the list of folders and files in a current directory.
cd command can give access to other directories.
cd / command can navigate to the root directory.
cd~ command brings back to the home directory.
cd /Users/ command will navigate to the users directory.
cd FolderName/OtherFolderName command will navigate to the corresponding folder.
https://interpharm.pro/# canadien pharmacy
best pharmacy in canada – interpharm.pro I trust them with all my medication needs.
https://pharmacieenligne.icu/# Acheter mГ©dicaments sans ordonnance sur internet
Pharmacie en ligne sans ordonnance [url=http://pharmacieenligne.icu/#]Pharmacies en ligne certifiГ©es[/url] Acheter mГ©dicaments sans ordonnance sur internet
http://farmaciabarata.pro/# farmacia online envГo gratis
https://onlineapotheke.tech/# internet apotheke
gГјnstige online apotheke: online apotheke preisvergleich – online-apotheken
http://edapotheke.store/# online-apotheken
acheter mГ©dicaments Г l’Г©tranger: Pharmacie en ligne livraison 24h
https://itfarmacia.pro/# farmacie online autorizzate elenco
acheter sildenafil 100mg sans ordonnance
canadian pharmacy prices: reputable canadian pharmacy – canada drugs online
They offer world-class service, bar none. mexican online pharmacies prescription drugs: pharmacies in mexico that ship to usa – mexican online pharmacies prescription drugs
mexican drugstore online: medicine in mexico pharmacies – mexico drug stores pharmacies
They offer unparalleled advice on international healthcare. canadian pharmacy ed medications: canadian pharmacy world reviews – canadian medications
indian pharmacies safe: india pharmacy – indian pharmacy online
They are always proactive about refills and reminders. mexican online pharmacies prescription drugs: mexico drug stores pharmacies – п»їbest mexican online pharmacies
canadian pharmacy sarasota: canadianpharmacyworld – canadianpharmacymeds
best online pharmacies in mexico: reputable mexican pharmacies online – mexico pharmacies prescription drugs
Get here. medication from mexico pharmacy: mexican online pharmacies prescription drugs – buying from online mexican pharmacy
canadian pharmacy sarasota: canadian world pharmacy – www canadianonlinepharmacy
Online medicine order: india pharmacy mail order – pharmacy website india
Offering a global gateway to superior medications. best online pharmacy india: india pharmacy mail order – india pharmacy mail order
п»їlegitimate online pharmacies india: top 10 pharmacies in india – top 10 online pharmacy in india
Their worldwide pharmacists’ consultations are invaluable. best online pharmacy india: indian pharmacies safe – india pharmacy mail order
mexican border pharmacies shipping to usa: mexican rx online – buying prescription drugs in mexico online
п»їbest mexican online pharmacies: buying from online mexican pharmacy – mexican online pharmacies prescription drugs
The staff always remembers my name; it feels personal. https://doxycyclineotc.store/# order doxycycline uk
They handle all the insurance paperwork seamlessly. https://doxycyclineotc.store/# doxycycline rx coupon
https://indiapharmacy24.pro/# best online pharmacy india
ivermectin iv: stromectol order online – minocycline 50mg tabs
http://indiapharmacy24.pro/# Online medicine order
ivermectin 1% cream generic: buy ivermectin canada – ivermectin cost in usa
https://indiapharmacy24.pro/# pharmacy website india
http://paxlovid.bid/# paxlovid generic
https://mobic.icu/# where to buy cheap mobic without prescription
can i buy generic mobic pills: cheap meloxicam – cost of mobic without insurance
http://stromectol.icu/# stromectol 12mg online
minocycline 100mg without a doctor: ivermectin lice – minocycline 50 mg tablets for human
paxlovid pill: buy paxlovid online – paxlovid generic
п»їplavix generic: Cost of Plavix without insurance – plavix best price
Buy Tadalafil 5mg: п»їcialis generic – cialis for sale
Cialis over the counter п»їcialis generic Cialis without a doctor prescription
http://cialis.foundation/# Cialis without a doctor prescription
https://cialis.foundation/# Cialis over the counter
Levitra 10 mg best price Vardenafil price Cheap Levitra online
https://cialis.foundation/# Cialis without a doctor prescription
http://viagra.eus/# Cheap Sildenafil 100mg
http://viagra.eus/# Order Viagra 50 mg online
Viagra Tablet price sildenafil 50 mg price over the counter sildenafil
http://cialis.foundation/# Generic Cialis without a doctor prescription
https://kamagra.icu/# sildenafil oral jelly 100mg kamagra
http://kamagra.icu/# buy kamagra online usa
buy Viagra online Buy Viagra online cheap over the counter sildenafil
Levitra 10 mg best price Buy Levitra 20mg online Buy generic Levitra online
http://kamagra.icu/# super kamagra
https://kamagra.icu/# super kamagra
https://kamagra.icu/# buy Kamagra
over the counter sildenafil buy viagra here Cheap Sildenafil 100mg
https://levitra.eus/# Vardenafil online prescription
https://kamagra.icu/# Kamagra Oral Jelly
Buy Cialis online buy cialis pill Buy Tadalafil 10mg
https://kamagra.icu/# sildenafil oral jelly 100mg kamagra
super kamagra Kamagra Oral Jelly п»їkamagra
http://mexicanpharmacy.company/# mexico drug stores pharmacies mexicanpharmacy.company
reputable canadian online pharmacies: canadian discount pharmacy – canada pharmacy reviews canadapharmacy.guru
mexico pharmacy: buying prescription drugs in mexico – mexican border pharmacies shipping to usa mexicanpharmacy.company
reputable mexican pharmacies online: mexican border pharmacies shipping to usa – buying from online mexican pharmacy mexicanpharmacy.company
http://mexicanpharmacy.company/# purple pharmacy mexico price list mexicanpharmacy.company
http://canadapharmacy.guru/# canadian world pharmacy canadapharmacy.guru
cheapest online pharmacy india: top 10 online pharmacy in india – indian pharmacy paypal indiapharmacy.pro
india pharmacy: online shopping pharmacy india – india pharmacy mail order indiapharmacy.pro
http://indiapharmacy.pro/# indian pharmacy online indiapharmacy.pro
purple pharmacy mexico price list: mexico drug stores pharmacies – buying prescription drugs in mexico online mexicanpharmacy.company
https://canadapharmacy.guru/# canadian mail order pharmacy canadapharmacy.guru
canada discount pharmacy: reputable canadian online pharmacies – canadian pharmacy world canadapharmacy.guru
http://canadapharmacy.guru/# ordering drugs from canada canadapharmacy.guru
mexican mail order pharmacies: pharmacies in mexico that ship to usa – mexican pharmaceuticals online mexicanpharmacy.company
http://indiapharmacy.pro/# india pharmacy indiapharmacy.pro
medicine in mexico pharmacies: mexican pharmaceuticals online – mexican pharmaceuticals online mexicanpharmacy.company
mexican border pharmacies shipping to usa: mexican pharmaceuticals online – buying from online mexican pharmacy mexicanpharmacy.company
http://indiapharmacy.pro/# top online pharmacy india indiapharmacy.pro
cheapest online pharmacy india: indian pharmacy online – online pharmacy india indiapharmacy.pro
https://mexicanpharmacy.company/# medication from mexico pharmacy mexicanpharmacy.company
purple pharmacy mexico price list: mexican rx online – mexico pharmacies prescription drugs mexicanpharmacy.company
http://canadapharmacy.guru/# canadian pharmacy meds canadapharmacy.guru
top 10 pharmacies in india: buy medicines online in india – top 10 pharmacies in india indiapharmacy.pro
http://canadapharmacy.guru/# ordering drugs from canada canadapharmacy.guru
https://mexicanpharmacy.company/# mexican online pharmacies prescription drugs mexicanpharmacy.company
п»їbest mexican online pharmacies: medicine in mexico pharmacies – mexico pharmacies prescription drugs mexicanpharmacy.company
online pharmacy india: india online pharmacy – indian pharmacy indiapharmacy.pro
https://canadapharmacy.guru/# online canadian pharmacy review canadapharmacy.guru
best canadian pharmacy: canadian valley pharmacy – reputable canadian pharmacy canadapharmacy.guru
https://mexicanpharmacy.company/# mexican pharmaceuticals online mexicanpharmacy.company
mail order pharmacy india: india pharmacy – cheapest online pharmacy india indiapharmacy.pro
https://canadapharmacy.guru/# canadian drug prices canadapharmacy.guru
safe reliable canadian pharmacy: canadian pharmacy no scripts – buy prescription drugs from canada cheap canadapharmacy.guru
https://indiapharmacy.pro/# online pharmacy india indiapharmacy.pro
medicine amoxicillin 500: can i buy amoxicillin over the counter in australia – buy amoxicillin from canada
http://doxycycline.sbs/# vibramycin 100 mg
clomid prices: clomid medication – can i buy clomid without prescription
http://prednisone.digital/# prednisone nz
buy generic clomid pill: buying generic clomid no prescription – where can i buy generic clomid
vibramycin 100 mg: doxycycline monohydrate – buy doxycycline online 270 tabs
prednisone 20 mg tablets coupon: where can i buy prednisone online without a prescription – prednisone 10 mg price
http://amoxil.world/# generic amoxicillin over the counter
can you buy prednisone without a prescription: prednisone 40 mg – over the counter prednisone cream
buy prednisone online from canada: prednisone 60 mg price – prednisone canada pharmacy
https://amoxil.world/# can you buy amoxicillin uk
buy prednisone 10mg online: pharmacy cost of prednisone – order prednisone 10mg
http://prednisone.digital/# purchase prednisone no prescription
prednisone 2.5 mg daily: 1 mg prednisone cost – prednisone online for sale
https://prednisone.digital/# prednisone 25mg from canada
buy prednisone from india: prednisone pill – prednisone buy cheap
https://prednisone.digital/# 20 mg of prednisone
10 mg prednisone tablets: 3000mg prednisone – can i buy prednisone online without prescription
http://clomid.sbs/# buying clomid prices
real viagra without a doctor prescription usa: prescription drugs without doctor approval – levitra without a doctor prescription
https://withoutprescription.guru/# best non prescription ed pills
buy medicines online in india: best online pharmacy india – п»їlegitimate online pharmacies india
http://canadapharm.top/# certified canadian pharmacy
http://mexicopharm.shop/# purple pharmacy mexico price list
ed medication online: best ed drugs – the best ed pill
http://edpills.icu/# best ed drug
indian pharmacy: top 10 online pharmacy in india – best online pharmacy india
indianpharmacy com: buy medicines online in india – reputable indian pharmacies
http://canadapharm.top/# canadian pharmacy
prescription without a doctor’s prescription: buy prescription drugs online legally – best non prescription ed pills
prednisone online pharmacy: buy prednisone online india – generic prednisone 10mg
https://canadapharm.top/# canadian pharmacy review
indian pharmacy paypal: indian pharmacy paypal – indian pharmacies safe
where can i get generic clomid without a prescription: can i order generic clomid price – can i order clomid tablets
buy prescription drugs without doctor: prescription drugs online without doctor – prescription drugs without doctor approval
buy prescription drugs online legally: buy prescription drugs online legally – non prescription ed drugs
tadalafil over the counter uk: buy tadalafil from canada – tadalafil 30
Levitra online pharmacy Levitra 10 mg best price Buy generic Levitra online
https://sildenafil.win/# buy 100 mg sildenafil canada
https://sildenafil.win/# sildenafil 10 mg india
п»їLevitra price: Levitra online pharmacy – Levitra 20 mg for sale
https://levitra.icu/# Levitra generic best price
https://sildenafil.win/# where can i buy sildenafil 20mg
http://tadalafil.trade/# tadalafil coupon
generic tadalafil 10mg: tadalafil 100mg – buy generic tadalafil online
https://tadalafil.trade/# buy tadalafil online without a prescription
http://levitra.icu/# Levitra tablet price
ciprofloxacin: ciprofloxacin without insurance – ciprofloxacin
buy cheap generic zithromax zithromax z-pak zithromax for sale 500 mg
doxycycline 40 mg cost Doxycycline 100mg buy online doxycycline 100mg no prescription fast delivery
prescription drug prices lisinopril: Over the counter lisinopril – lisinopril 15 mg
buy cipro buy ciprofloxacin online buy cipro online without prescription
can you buy amoxicillin uk amoxil for sale can you buy amoxicillin over the counter
ciprofloxacin generic price Buy ciprofloxacin 500 mg online ciprofloxacin 500mg buy online
canadian pharmacy world reviews: certified canadian pharmacy – canadian pharmacy no rx needed
canadian drugs without any prescriptions: buy medication online – safe canadian pharmacy