Thuta Learning
IntermediateDevOps & Toolsbeginner

Environment Variables & PATH

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Get comfortable with environment variables & PATH — no need to fear them
  • Practice running the commands yourself in the terminal
  • See how these commands come in handy on a real server or project

Let's think about it this way for a second

An environment variable is key-value data the shell keeps track of — things like $HOME (your home folder path), $USER (your username), and $PATH (the list of folders to search for programs) store system-wide settings. The moment you type a command like python3, the shell searches through the folders listed in $PATH in order, and as soon as it finds the python3 executable, it runs it — a program in a folder that's not on PATH can't be run by name alone (you'd need to write the full path, or prefix it with ./). export VAR=value creates a new variable and stores it just for that terminal session — it disappears once you close the terminal.

Let's connect this to a real-world scenario

Running echo $HOME or echo $PATH shows you your system's settings directly. If you don't want your environment variables disappearing every time you close the terminal, you need to add an export line to your ~/.bashrc file — since .bashrc loads first every time you open a new terminal, it'll feel like a permanent setting (you'll run into .bashrc again in later chapters). Keeping sensitive data like API keys and database passwords as environment variables instead of hardcoding them into your code is a good security practice.

Let's try it together in the terminal

bash
echo $HOME
echo $PATH
export MY_NAME="Alice"
echo $MY_NAME
export PATH=$PATH:$HOME/scripts   # folder အသစ်ကို PATH ထဲ ထပ်ထည့်
You should see
Running echo $PATH will show a list of folder paths separated by colons (:).

5-Minute Try-It

Run export MY_NAME="your name" and check it with echo $MY_NAME. Then close the terminal, reopen it, and check whether the variable still exists.

A Quick Word of Caution

If you overwrite the PATH variable with something like export PATH=/only/one/folder, you might not even be able to run ls or cd anymore — always include the existing $PATH ($PATH:...).

Easy traps

  • Assuming that once you run export, the setting becomes permanent — it disappears when you close the terminal; it only becomes permanent once you add it to .bashrc
  • When adding a folder to $PATH, writing just $HOME/scripts instead of $PATH:$HOME/scripts, which wipes out all the old folders (so no commands work anymore)

Now Try It Yourself

Run export MY_NAME="your name" and check it with echo $MY_NAME. Then close the terminal, reopen it, and check whether the variable still exists.

You'll know it worked when: Running echo $PATH will show a list of folder paths separated by colons (:).

Environment Variables & PATH | Thuta Learning