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

Linux Shell Configuration: .bashrc, .zshrc, and Beyond

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. In this post you'll learn how shell configuration files like .bashrc and .zshrc work, how to make PATH changes permanent, and how to get a proper local setup: WSL 2 for Windows users, and a terminal emulator you'll actually enjoy.

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!

What Is a Shell Configuration File?

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.

Make Your PATH Changes Permanent

If you change your PATH variable with export in your current shell session, there's a catch: the next time you restart your shell, it gets reset to its default value.

The most common way to change your PATH permanently is to add the export command to your shell's configuration file:

export PATH="$PATH:/absolute/path/to/directory"

This appends to PATH, it doesn't replace it. Use double quotes so $PATH expands to your current PATH. Single quotes would write literal $PATH string instead... not what you want.

Then restart your shell session, or run source ~/.zshrc or source ~/.bashrc to reload the config in place. If you want the full story on how PATH and environment variables work, we've got a whole post on the PATH variable.

Windows Users: Install WSL 2

The built-in Windows command prompt is terrible (in my opinion). It's so bad that if you're on Windows I recommend you just install WSL 2 (Windows Subsystem for Linux) and Ubuntu. This will allow you to keep using your normal Windows desktop but also have a Linux command line, operating system, and filesystem for your programming work.

WSL 2 was a huge step forward for developers on Windows. You get a full Linux operating system and command line experience without the need to dual boot. WSL is an official Microsoft product: it won't mess up your base Windows install. You'll still be able to run Steam...

Here are a couple of things to keep in mind about WSL 2:

  • There are two versions of WSL. Use the latest: version 2.
  • The WSL 2 filesystem is completely separate from your Windows file system. Use your normal Windows file system normally: for games, documents, Windows apps, whatever. I recommend using the Linux filesystem for all your code.

To install it, open the Command Prompt as administrator, run wsl --install, and follow the prompts (the official WSL installation guide covers the details). Ubuntu will ask you to create a username and password: don't forget them, you'll need that password every time you run a sudo command.

Which Terminal Emulator Should You Use?

The default terminal that came with your operating system is fine. However, there are other options worth knowing about (a terminal emulator is not the same thing as a shell, by the way):

  • Editor built-ins: Most text editors for developers have a built-in terminal. VS Code, Zed, and Cursor are popular text editors that also have a built-in terminal. I use Zed's terminal for most of my coding work.
  • Ghostty: A very new terminal emulator that differentiates itself by being fast, feature-rich, and native. It's a great option if you love to customize, and want a modern, fast terminal.
  • Alacritty: Known for its speed and extensibility. Before Ghostty, Alacritty was the go-to terminal for many developers who wanted a fast and customizable terminal.
  • Windows Terminal: The terminal emulator for Windows. Be sure to start WSL whenever you open a new terminal window.

With a config file you understand, a permanent PATH, and a terminal you like, your shell finally starts feeling like your shell. Good next steps for rounding out your local setup are learning to read man pages, using symlinks to organize your dotfiles, and knowing how to kill a runaway process — or just work through the whole Learn Linux course and get all of it hands-on.

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 add a directory to my PATH permanently?

Add an export line like export PATH="$PATH:/path/to/directory" to your shell's configuration file (.bashrc for Bash, .zshrc for Zsh). The config file runs on every new shell session, so the change sticks. Reload it in your current session with source ~/.bashrc or source ~/.zshrc.

Should I use WSL 1 or WSL 2?

Use WSL 2. It is the current version of the Windows Subsystem for Linux and gives you a full Linux operating system, command line, and filesystem alongside your normal Windows desktop. Install it by running wsl --install in an administrator Command Prompt.

Related Articles