System software and applications use a set of environment variables in order to fast access certain information. These variables serve as a storage and when software invoke them, they simply pass the stored information. Linux has a complete range of most common environment variables. The purpose of these common variables is to change the stored information for accommodating changed conditions. For example, below are the most commonly used environment variables in Linux:
|Variable Name||Purpose of the Variable|
|Display||Name of the graphical environment|
|Editor||Preferred text editor|
|Shell||Name of the shell program|
|Home||Stored path of the home directory|
|Lang||Preferred system language|
|User||Stores your username|
|Browser||Path to the default browser|
|Bash_version||displays the version of the bash shell used|
|Path||Displays a colon-separated list of the paths of the user executable programs|
Set Environment Variable in Linux
After knowing the most common environment variables in Linux, now you need to know how to alter those variables. Sometimes a certain software fails to run because it can’t find the required variable, or it’s unable to process the information stored within. Below are the most common commands related to environment variable in Linux:
|Command||Purpose of Command|
|env||Lists all the environment variables in terminal|
|export||Exports the value of a newly assigned environment variable to the system|
|set||Changes the flags of environment variables as defined by the user for example set -a is used to mark variables that are modified or created for export.|
|unset||Removes the associated flags of an environment variable|
For example, let’s learn how to modify the HOME environment variable. Use the following command in the terminal:
After you’ve set the value of environment variable HOME now you need to export it for other programs to use it, following command works:
This will export your new data to the other programs and subshells. Similarly, $ANDROID_HOME is another variable which is used while running Android SDK used for developing android applications. You can set it using the following command:
It gives the home directory/Android/Sdk path to the executing program while building Android applications. Note that $ dollar sign is not followed when you set an environment variable’s value.
If you want to change an environment variable in Linux then it’s an easy task. You can simply launch a terminal, set the new value and later export it to make it useable for other programs. If you want to do the same on Mac OS Catalina then read: Learn how to set a permanent environment variable in Catalina. Similarly, you can also add environment variables on Windows 10.
It’s important to know that if your environment variable in linux resets after restart then you need to add a persistent one. For that purpose, you need to find your shell file in your home directory, in most cases its path is ~/.bash_profile or simply ~/.profile. Adding your variables inside the file will make sure that they remain persistent on every restart.