When you open a terminal on Linux, your shell quietly keeps a list of named settings that programs can read. These settings are called environment variables in Linux, and they control simple things like which language your system speaks, where your home folder is, and where Linux looks for programs when you type a command. In this friendly guide you will learn what environment variables are, how to see them, how to create your own, and what the famous PATH variable actually does.
What Are Environment Variables in Linux? – Environment Variables and the PATH in
An environment variable is a name-and-value pair, written like NAME=value. Think of it as a sticky note that your shell (the program behind your terminal, usually called Bash) keeps on the wall. Any program you start from that terminal can read those sticky notes.
Here are a few variables that already exist on your system right now:
HOME– the location of your home directory, for example/home/alexUSER– your usernameLANG– the language and character encoding your system usesPATH– a list of folders where Linux searches for programs (we will explore this one in detail below)
Programs use these values to behave correctly. When a program wants to save something “in your home folder”, it simply reads the HOME variable instead of asking you every time.
Seeing Your Environment Variables in Linux with printenv and echo – Environment Variables and the PATH in
To see the whole list of environment variables in Linux, run:
printenv
You will get a long list of lines like HOME=/home/alex. To look at just one variable, use echo with a dollar sign in front of the name:
echo $HOME
echo $USER
The dollar sign means “give me the value stored in this variable”. Without the dollar sign, echo HOME would simply print the word HOME. This small detail trips up almost every beginner, so remember it: $NAME means the value, NAME alone is just the name.
Setting Environment Variables in Linux for One Session
You can create your own variable in two steps. First, type:
MYNAME="Alex"
Notice there are no spaces around the equals sign. That is a strict rule in Bash. Now echo $MYNAME prints Alex. However, this variable currently exists only inside your shell. Programs you start from the terminal will not see it yet. To share it with programs, you “export” it:
export MYNAME="Alex"
You can also do both steps at once exactly like that. Try it: open a program such as nano after exporting, and it will inherit the variable. Keep in mind that all of this is temporary. When you close the terminal, the variable disappears. That is normal and expected.

What Is the PATH Variable and Why Does It Matter?
PATH is the most important of all environment variables in Linux. It is a list of folders, separated by colons, where the shell searches for programs when you type a command. Look at yours:
echo $PATH
You will see something like /usr/local/bin:/usr/bin:/bin:/usr/sbin. When you type ls, the shell checks each of these folders, in order, until it finds a program named ls (it lives in /usr/bin/ls). If the folder is not listed in PATH, the shell answers “command not found” even though the program exists.
This explains a classic beginner moment: you download or build a program inside your home folder, type its name, and Linux says it does not exist. The fix is to add its folder to PATH for the current session:
export PATH="$HOME/myprograms:$PATH"
This tells the shell: “look in my folder first, then in all the old places.” After that, typing the program name works.
Making Variables Permanent with .bashrc
Typing export commands every morning would be painful. Luckily, Bash reads a file named .bashrc in your home directory every time a new terminal opens. Add your export lines at the end of that file and they will be applied automatically:
export EDITOR=nano
export PATH="$HOME/myprograms:$PATH"
Setting EDITOR here is a nice bonus: many tools open this editor when they need you to type something. Environment variables are also how programs receive secrets such as API keys without hard-coding them into files. If you later play with scripts that call online services, you will see this pattern everywhere, for example when calling an LLM API from Bash, where the key is read from a variable instead of being written into the script.
Common Beginner Mistakes
- Adding spaces around =.
MYNAME = "Alex"fails; Bash treats it as a command. Always writeMYNAME="Alex". - Forgetting the dollar sign.
echo HOMEprints the word HOME, not your folder path. - Overwriting PATH completely. If you write
export PATH="/some/folder"you erase the whole list and basic commands stop working. Always keep$PATHin the new value, as shown above. - Expecting variables to survive a reboot. Session variables are temporary by design; permanent ones belong in
.bashrc. - Lowercase vs uppercase confusion. Names are case-sensitive. By convention, environment variables use UPPERCASE so they stand out from regular shell variables.
Conclusion
Environment variables in Linux are simply named settings that your shell shares with programs. You can view them with printenv, read one with echo $NAME, create one with export NAME="value", and make it permanent by adding it to .bashrc. The PATH variable deserves special attention because it decides where Linux looks for the commands you type. If you want to go deeper into how the shell itself works, the official environ manual page lists the classic variables every Linux user should know.