Menu
Coddy logo textTech

The Profile File

Part of the Fundamentals section of Coddy's Terminal journey — lesson 64 of 82.

Variables you set and export only last until you close the terminal. To make them permanent, you need to add them to a profile file that runs automatically when you start a new shell session.

The most common profile file is ~/.bashrc for Bash shells or ~/.zshrc for Zsh. These files are shell scripts that execute every time you open a new terminal. You can view your profile file with:

cat ~/.bashrc

To add a permanent environment variable, append an export statement to your profile file:

echo 'export MY_VAR="hello"' >> ~/.bashrc

The single quotes prevent the shell from expanding the variable now, and the appends to the file instead of overwriting it. After adding to the profile, the change won't take effect in your current session. You need to either open a new terminal or reload the file with:

source ~/.bashrc

The source command executes the file in your current shell, applying any new variables or settings immediately. This is how developers customize their terminal environment with personal preferences, shortcuts, and configurations that persist across sessions.

challenge icon

Challenge

Easy

Add a permanent environment variable to your profile file, then reload it to apply the changes.

First, append an export statement to ~/.bashrc that sets a variable called WORKSPACE with the value /home/user/projects. Use single quotes around the entire export statement to prevent variable expansion.

Then, use the source command to reload the profile file so the variable takes effect immediately.

Finally, use echo to display the value of your new WORKSPACE variable.

Your final output should be:

/home/user/projects

Hint: Use echo 'export WORKSPACE="/home/user/projects"' >> ~/.bashrc to append, then source ~/.bashrc to reload, and finally echo $WORKSPACE to verify.

Cheat sheet

Environment variables set with export only last until the terminal closes. To make them permanent, add them to a profile file like ~/.bashrc (Bash) or ~/.zshrc (Zsh).

View your profile file:

cat ~/.bashrc

Append a permanent environment variable to your profile:

echo 'export MY_VAR="hello"' >> ~/.bashrc

Use single quotes to prevent variable expansion, and to append (not overwrite).

Reload the profile file to apply changes immediately:

source ~/.bashrc

The source command executes the file in your current shell, applying new variables without opening a new terminal.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals