Customize Your .zshrc on Mac: Aliases, PATH, Prompt
Every time you open a Terminal window on your Mac, zsh reads ~/.zshrc and runs whatever it finds there. That makes it the single best place to shape your command line: shortcuts for long commands, extra folders on your PATH, a prompt that tells you where you are. macOS does not create the file for you — here is how to build one worth keeping.
Create or open the file
- Open Terminal (Applications → Utilities, or search Spotlight).
- Run
nano ~/.zshrc. If the file does not exist, nano starts a blank one at the right path. - Add your lines, then press Ctrl+O and Return to save, and Ctrl+X to exit.
- Apply the changes to your current window with
source ~/.zshrc— no need to open a new one.
The file is hidden in Finder because its name starts with a dot; press Cmd+Shift+. in your home folder to see it. Everything after a # on a line is a comment, so annotate freely.
Aliases worth stealing
An alias is a nickname for a longer command. The syntax is alias name='command' — no spaces around the equals sign:
# listing and navigation
alias ll='ls -lah'
alias ..='cd ..'
# one word to update everything Homebrew manages
alias update='brew update && brew upgrade'
# your local IP address, instantly
alias myip='ipconfig getifaddr en0'
To remove an alias, delete its line from ~/.zshrc and run source ~/.zshrc again — or run unalias ll to drop it from the current session only. Aliases only exist in shells that have read the file, so scripts and other apps never see them.
Add to your PATH the right way
PATH is the list of folders zsh searches when you type a command. To add one, prepend it and keep the existing value:
# add a personal bin folder ahead of system paths
export PATH="$HOME/bin:$PATH"
# check the result
echo $PATH
Never write export PATH="$HOME/bin" on its own — that replaces the whole list and breaks every command until you fix it. If you do, close the window, reopen Terminal, and correct the line; the mistake only persists if it is saved in the file.
One refinement: macOS Terminal windows are login shells, which read ~/.zprofile first and then ~/.zshrc. Environment variables like PATH only need setting once, so the tidy convention is PATH exports in .zprofile, aliases and interactive options in .zshrc. Homebrew's installer follows this and writes its shellenv line to .zprofile. Putting everything in .zshrc also works — it is just re-run for every subshell.
A prompt that earns its place
zsh builds its prompt from the PROMPT variable. The default shows your machine name and the current folder; a cleaner minimal version:
# current folder, then %% (or # as root)
PROMPT='%1~ %# '
# undo: restore the macOS default prompt
PROMPT='%n@%m %1~ %# '
%n is your username, %m the Mac's name, %1~ the current directory's last component, and %# the prompt character. Two quality-of-life options worth adding beneath it: setopt SHARE_HISTORY to share command history across tabs, and setopt CORRECT to catch command typos.
Two commands keep you honest while you experiment: alias on its own lists every alias currently active, and type ll tells you what any name actually resolves to — worth checking before you shadow a real command with a nickname you'll forget you wrote.
Your shell deserves a dotfile; your Mac's settings don't have to. Mainspring turns 90+ hidden macOS tweaks into labelled, reversible toggles — no defaults commands, no reloading.
Try Mainspring free →Signed & notarized by Apple · 1-day free trial · $29 once
If you break something
A bad .zshrc line prints an error at the top of every new window but rarely locks you out. Comment out the suspect line with #, save, and source ~/.zshrc. In the worst case, zsh -f starts a shell that skips all config files so you can repair yours calmly — nano is the easiest editor for the job.