This article covers how to set and unset both local and persistent environment variables in Linux. In fact, every time you start a shell session in Linux, the system goes through configuration files and sets up the environment accordingly. Environment variables play a significant role in this process.
Environment variables are a set of key value pairs stored on your Linux and used by processes in order to be able to perform specific operations. with the export command but also by modifying some system files to make them persistent.
How to Set Environment Variables on Linux using export ?
The easiest way to set environment variables is to use the export command:
$ export VAR="value"
How to Unset Environment Variables on Linux Using unset command ?
To unset an environment variable, use the unset command with the following syntax:
$ unset <variable>
Common Set of Environment Variables on Linux:
- USER : the current username of the user using the system;
- EDITOR : the program run to perform file edits on your host;
- HOME : the home directory of the current user;
- PATH : a colon separated list of directories where the system looks for commands;
- PS1 : the primary prompt string (to define the display of the shell prompt);
- PWD : the current working directory;
- _ : the most recent command executed on the system (by the user)
- MAIL : the path to the current user’s mailbox;
- SHELL : the shell used in order to interpret commands on the system, it can be many different ones (like bash, sh, zsh or others);
- LANG : the language encoding used on the system;
- DESKTOP_SESSION : the current desktop used on your host (GNOME, KDE)
- HISTFILESIZE : number of lines of command history stored in the history file;
- HISTSIZE : number of lines of history allowed in memory;
- UID : the current UID for the user.