0
0
Linux CLIscripting~5 mins

PATH variable management in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes your computer cannot find the programs you want to run because it does not know where to look. The PATH variable tells your system where to find these programs. Managing the PATH variable helps you run commands easily without typing full paths.
When you install a new program and want to run it from any folder without typing its full location
When you want to add a folder with your own scripts to run them quickly
When a command is not found because its folder is missing from PATH
When you want to check which folders your system searches for commands
When you want to temporarily add a folder to PATH for a single session
Commands
This command shows the current list of folders where your system looks for commands. It helps you see what is already set.
Terminal
echo $PATH
Expected OutputExpected
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
This command adds the folder /home/user/my-scripts to the end of the PATH variable for the current session, so you can run scripts from there without typing the full path.
Terminal
export PATH=$PATH:/home/user/my-scripts
Expected OutputExpected
No output (command runs silently)
Check again to confirm that the new folder was added to PATH.
Terminal
echo $PATH
Expected OutputExpected
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/my-scripts
Open the .bashrc file to add the PATH change permanently so it applies every time you open a terminal.
Terminal
nano ~/.bashrc
Expected OutputExpected
No output (command runs silently)
Reload the .bashrc file to apply the PATH changes immediately without restarting the terminal.
Terminal
source ~/.bashrc
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: PATH tells your system where to find commands, and you can add folders to it to run your programs easily.

Common Mistakes
Overwriting PATH without including the old value, like export PATH=/new/path
This removes all existing folders from PATH, causing many commands to stop working.
Always include the old PATH value when adding new folders, like export PATH=$PATH:/new/path
Adding folders to PATH only in the current session without saving to .bashrc
The change disappears when you close the terminal, so you have to add it again next time.
Add the export command to your ~/.bashrc file to make it permanent.
Adding invalid or non-existent folders to PATH
It can slow down command lookup and cause confusion if commands are missing.
Check that the folder exists before adding it to PATH.
Summary
Use echo $PATH to see which folders your system searches for commands.
Add new folders to PATH with export PATH=$PATH:/new/folder to run programs easily.
Make PATH changes permanent by adding export commands to ~/.bashrc and reloading it.