Script Valley
Developer Environment Setup (WSL, Terminal, VS Code)
Linux Terminal FundamentalsLesson 2.4

How to use environment variables and the PATH in Linux

environment variables, echo $VAR, export command, PATH variable, which command, permanent vs session-only variables, .bashrc and .zshrc

Environment Variables and PATH

Linux PATH variable diagram

Environment variables are key-value pairs the shell and every program it launches can read. PATH is the most important one โ€” it controls which programs you can run by name.

Reading variables

echo $HOME
echo $USER
echo $PATH

Setting a variable for the current session

export MY_API_KEY=abc123
echo $MY_API_KEY

Variables set with export are visible to child processes. Without export, they are only visible in the current shell.

Making variables permanent

Add export lines to ~/.bashrc then reload:

echo 'export MY_API_KEY=abc123' >> ~/.bashrc
source ~/.bashrc

Finding where a command lives

which node
which python3

When a command is not found, the binary is either not installed or its directory is not in $PATH. Add it permanently:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Up next

How to use permissions and sudo in Linux

Sign in to track progress

How to use environment variables and the PATH in Linux โ€” Linux Terminal Fundamentals โ€” Developer Environment Setup (WSL, Terminal, VS Code) โ€” Script Valley โ€” Script Valley