List of Environment Variables in Linux/Unix

โšก Smart Summary

Environment variables in Linux and Unix are dynamic named values that shape how programs and the shell behave, storing settings such as your PATH, home directory, default editor, language, and the shell currently in use.

  • ๐ŸŒฑ What they are: Environment variables hold dynamic values that affect processes and can be created, edited, and deleted.
  • ๐Ÿงญ PATH: The PATH variable lists the directories the shell searches to find and run executable commands.
  • ๐Ÿ”Ž Reading values: The echo command shows one variable, while env and printenv list all environment variables.
  • ๐Ÿ†• Creating: Assign a value with NAME=value, then use export to make it available to child processes.
  • ๐Ÿ—‘๏ธ Deleting: The unset command removes a variable and its value from the current shell session.
  • ๐Ÿ’พ Persistence: Add export lines to ~/.bashrc or /etc/environment to keep variables across sessions.
  • ๐Ÿค– AI help: AI assistants and GitHub Copilot can audit variables and generate shell scripts that use them.

List of common environment variables in Linux and Unix

Environment variables are one of the first things worth understanding on any Linux or Unix system, because they quietly control how your programs and shell behave. This guide explains what they are, the most common ones, and how to read, create, and delete them.

What is a Computing Environment?

The computing environment is the platform (platform = operating system + processor) where a user can run programs.

What is a Variable?

In computer science, a variable is a location for storing a value, which can be a filename, text, number, or any other data. It is usually referred to by its symbolic name, which is given to it at creation. The value stored can then be displayed, deleted, edited, and re-saved.

Variables play an important role in computer programming because they enable programmers to write flexible programs. Because they are tied to the operating system you work on, it is important to know some of them and how you can influence them.

What are Environment variables?

Environment variables are dynamic values that affect the processes or programs on a computer. They exist in every operating system, but the types may vary. Environment variables can be created, edited, saved, and deleted, and they give information about the system behavior.

Environment variables can change the way software and programs behave. For example, the $LANG environment variable stores the language that the user understands. This value is read by an application so that a Chinese user is shown a Mandarin interface while an American user is shown an English interface.

Let us study some common environment variables:

Variable Description
PATH This variable contains a colon (:)-separated list of directories in which your system looks for executable files. When you enter a command in the terminal, the shell looks for the command in the directories listed in the $PATH variable. If the command is found, it executes. Otherwise, it returns with an error ‘command not found’.
USER The username
HOME Default path to the user’s home directory
EDITOR Path to the program that edits the content of files
UID User’s unique ID
TERM Default terminal emulator
SHELL Shell being used by the user

Accessing Variable values

To determine the value of a variable, use the echo command:

echo $VARIABLE

For example, the screenshot below shows the value of the PATH variable displayed with the echo command.

Displaying the PATH variable value with the echo command

Any environment variable can be read the same way. The output below shows echo returning the value of a variable.

Output of the echo command showing an environment variable value

Variables are case-sensitive, so make sure you type the variable name in the correct letter case; otherwise you may not get the desired result. To list every environment variable at once, use the env command, as shown below.

The env command listing all environment variables in the terminal

Set New Environment Variables

You can create your own user-defined variable with this syntax:

VARIABLE_NAME=variable_value

Again, remember that variable names are case-sensitive and are usually written in uppercase. A variable created this way is a local shell variable that only the current shell can see. To promote it to an environment variable that child processes also inherit, use the export command:

export VARIABLE_NAME=value

The screenshot below shows a new variable being created and then displayed with echo.

Creating and displaying a new user-defined environment variable

Deleting Variables

The following syntax removes a variable from the system:

unset variablename

This removes the variable and its value from the current shell session, as shown below.

Removing an environment variable with the unset command

FAQs

A shell variable exists only in the current shell and is not passed to other programs. An environment variable is a shell variable that has been exported, so child processes started from that shell inherit it. Use the export command to promote a variable.

Variables set in the terminal disappear when you close the session. To keep them, add the export line to a startup file: ~/.bashrc or ~/.profile for a single user, or /etc/environment for every user on the system. Reload the file or reopen the terminal to apply it.

Append the new directory to the existing PATH so you do not overwrite it: export PATH=$PATH:/your/new/directory. This adds your folder to the list the shell searches for commands. Put the same line in ~/.bashrc to make the change survive new sessions.

printenv lists only environment variables and can show a single one, such as printenv HOME. The env command also lists environment variables and can run a program with a modified environment. The set command shows everything, including shell variables and functions, not just exported ones.

This usually means you overwrote PATH instead of appending to it, so the shell can no longer find standard commands. Always include $PATH when setting it. To recover in the current session, run export PATH=/usr/local/bin:/usr/bin:/bin, then fix your startup file.

It is convenient but risky. Environment variables can be read from /proc, are inherited by child processes, and often leak into logs or crash reports. For sensitive secrets, prefer a dedicated secret manager or an encrypted file with restricted permissions instead of a plain variable.

AI assistants can explain what an unfamiliar variable does, audit configuration files for missing or duplicated entries, and flag secrets accidentally exposed in variables. Machine-learning tools can also scan process environments across many servers to detect misconfigurations that would be tedious to review by hand.

Yes. GitHub Copilot can generate export statements, ~/.bashrc edits, and shell scripts that read variables such as $HOME or $PATH. It suggests the syntax as you type, though you should review any code that handles credentials before you run it.

Summarize this post with: