Persistent Configuration

ShellBeginner
Practice Now

Introduction

In previous labs, configs disappeared when the terminal closed. This is like a hotel room—it resets.

To make changes stick, we write them into a specific configuration file.

This is an important operating habit. Temporary changes are good for experimentation, but long-term shell behavior usually belongs in startup files that the shell reads when sessions begin.

Different shells use different files:

  • Zsh (LabEx default): ~/.zshrc.
  • Bash: ~/.bashrc.

This difference matters because "the shell" is not one single universal program. Each shell has its own conventions, startup rules, and configuration files.

In this lab, you will:

  • Modify Zsh config.
  • Switch to Bash.
  • Modify Bash config.

Edit Zsh Config (.zshrc)

The default LabEx shell is Zsh. Its config file is ~/.zshrc.

  1. Open ~/.zshrc:
nano ~/.zshrc
  1. Scroll to the bottom and add:
alias hellozsh='echo Hello from Zsh'
  1. Save and exit (Ctrl + O -> Enter -> Ctrl + X).

You wrote the config, but the shell hasn't read it yet.

Editing a configuration file changes the file on disk, but it does not instantly change the behavior of the running shell. The shell must read that file again before the new settings take effect.

Reload Config (source)

Force the shell to reload its config file using source.

The source command tells the current shell to read commands from a file and execute them in the current session rather than in a new child process.

  1. Reload:
source ~/.zshrc
  1. Test your new alias:
hellozsh

Output:

Hello from Zsh

This alias is now persistent for Zsh.

Switch to Bash

Now, try specific shell isolation.

  1. Switch to Bash:
bash
  1. Try running the Zsh alias:
hellozsh

Output: command not found.

It fails because Bash only looks at ~/.bashrc.

This is a good reminder that shell customizations are often shell-specific. A setting you create for one shell does not automatically become universal.

Edit Bash Config (.bashrc)

Let's configure Bash.

  1. Open .bashrc:
nano ~/.bashrc
  1. Add this alias at the bottom:
alias hellobash='echo Hello from Bash'
  1. Save and exit.

  2. Reload Bash config:

source ~/.bashrc
  1. Test it:
hellobash

Output: Hello from Bash.

  1. Exit Bash to return to Zsh:
exit

Summary

In this lab, you learned how to personalize your Linux environment permanently:

  • Shell Specifics: Different shells (Zsh, Bash) use different configuration files (.zshrc, .bashrc).
  • Persistence: Changes made in a terminal session are temporary unless saved to these files.
  • Source: Using source allows you to apply changes immediately without restarting the terminal.

You now understand how to customize your environment, no matter which shell you are using!