We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

.bashrc vs .zshrc: Shell Configuration Files

Boot.dev Team
Boot.dev TeamProgramming course authors and video producers

Last published

Table of Contents

Your shell runs a configuration file every single time it starts, and once you know how to edit it, you can customize almost everything about your command line experience. Bash uses .bashrc, while Zsh uses .zshrc. You'll learn how to edit and reload these files and use them to create persistent aliases.

All the content from our Boot.dev courses are available for free here on the blog. This one is the "Local CLI" chapter of Learn Linux. If you want to try the far more immersive version of the course, do check it out!

.bashrc vs .zshrc

Bash and Zsh both have configuration files that run automatically each time you start a new shell session. These files are used to set up your shell environment. They can be used to set up aliases, functions, and environment variables.

These files are located in your home directory (~) and are hidden by default. The ls command has a -a flag that will show hidden files:

ls -a ~
  • If you're using Bash, .bashrc is probably the file you want to edit.
  • If you're using Zsh, .zshrc is probably the file you want to edit or create if it doesn't yet exist.

Which one do you have? Linux distros typically default to Bash, while macOS has shipped with Zsh as the default since Catalina. If you're not sure, run echo $SHELL and see which one comes back.

How to Edit Your .bashrc or .zshrc

You can use the nano command to edit files right in your terminal:

nano ~/.bashrc
# or, if you're using Zsh:
nano ~/.zshrc

In nano, use Ctrl+O to save the file (confirm any prompts with Enter), then Ctrl+X to exit. The command list is at the bottom of the screen.

Not sure which config file your shell is actually loading? There's a simple trick to confirm it. Add the following line to the bottom of the file you think is your shell configuration file:

echo "Hello from the shell!"

Close your terminal and open a new one. If you see the message Hello from the shell!, you've found the right file! Just remember to remove the line afterward so you don't see that message every time you open a new shell.

Reload .bashrc or .zshrc

You don't need to close your terminal after every edit. Run source with the file that belongs to your shell:

source ~/.bashrc
# or
source ~/.zshrc

This executes the configuration file in your current shell, so its changes take effect immediately. Opening a new shell session works too.

What Is a Shell Alias?

A shell alias is a command shortcut. Aliases are useful for shortening commands you run all the time. Maybe you always run ls with the same flags:

alias ll="ls -la"

Now you can run ll, and the shell will expand it to ls -la. This creates a temporary alias for the current shell session. Running alias without any arguments lists all the aliases in your current session:

alias

You can remove an alias with unalias:

unalias ll

To make the ll alias persistent, add alias ll="ls -la" to your shell configuration file and reload it as described above. Aliases should make commands shorter, not surprising, so don't create an alias for a destructive command like rm that quietly adds aggressive flags.

If you're editing your shell config to make a PATH change permanent, the PATH environment variable article covers the exact export command and how to avoid overwriting your existing directories. And if you're choosing between a shell and a terminal emulator, Shell vs Terminal explains why changing one doesn't change the other.

Frequently Asked Questions

What is the difference between .bashrc and .zshrc?

They do the same job for different shells. .bashrc is the configuration file that Bash runs when it starts a new session, and .zshrc is the equivalent for Zsh. Both live in your home directory and are used to set up aliases, functions, and environment variables. Edit the one that matches your shell — run echo $SHELL if you are not sure which one you have.

Do I need to restart my terminal after editing .bashrc or .zshrc?

You either need to open a new terminal session or reload the file in your current one by running source ~/.bashrc (or source ~/.zshrc). Config files only run automatically when a new shell session starts, so changes do not take effect in already-open sessions until you source the file.

Where is the shell configuration file on macOS?

macOS uses Zsh as the default shell, so your configuration file is ~/.zshrc in your home directory. It is hidden by default, so use ls -a to see it, and create it if it does not exist yet.

How do I know whether to edit .bashrc or .zshrc?

Run echo $SHELL. Edit .bashrc if it reports Bash or .zshrc if it reports Zsh.

How do I make a shell alias permanent?

Add the alias to ~/.bashrc if you use Bash or ~/.zshrc if you use Zsh. Open a new terminal session or reload the matching file with source ~/.bashrc or source ~/.zshrc.

Related Articles