Permanently Unsetting Environment Variables
In the previous step, you learned how to temporarily unset an environment variable for your current session. Now, you will learn how to permanently unset a variable by modifying the configuration files where it is defined.
Locating the Variable Definition
First, let's find where the OLD_TRADE_DATA
variable is defined. In this lab, it has been added to your .zshrc
file, which is located in your home directory. Let's view this file:
nano ~/.zshrc
This opens the .zshrc
file in the nano text editor. Scroll through the file and look for a line that contains OLD_TRADE_DATA
. You should find a line like this:
export OLD_TRADE_DATA="Outdated Info"
Modifying the Configuration File
To permanently unset the variable, you have two options:
-
Comment out the line by adding a #
at the beginning:
#export OLD_TRADE_DATA="Outdated Info"
-
Delete the line completely by positioning your cursor at the beginning of the line and pressing Ctrl+K
to cut the entire line.
For this lab, let's use the first approach. Add a #
at the beginning of the line to comment it out.
After making the changes, save the file by pressing Ctrl+O
, then Enter
, and exit nano by pressing Ctrl+X
.
Applying the Changes
After modifying the configuration file, you need to reload it for the changes to take effect in your current session. Use the source
command:
source ~/.zshrc
Verifying the Changes
To verify that the variable is permanently unset, check its value again:
printenv OLD_TRADE_DATA
There should be no output, indicating that the variable is no longer set.
To further verify that the changes will persist across new terminal sessions, you can open a new terminal window or tab and check the variable:
printenv OLD_TRADE_DATA
Again, there should be no output, confirming that the variable is permanently unset.
Congratulations! You have successfully learned how to permanently unset environment variables in Linux by modifying configuration files.