When you type a command into a Linux terminal, what’s really happening is that a program is being executed. Normally, to execute a custom program or script, we need to use its full path, such as /path/to/script.sh
or just ./script.sh
if we’re already in its residing directory. Alternatively, we can execute a lot of commands without specifying paths, like uptime
or date
, etc.
The reason we don’t need to specify paths for some commands is because of the $PATH
variable. This is a variable that can be configured to tell our Linux system where to look for certain programs. That way, when typing date
into the terminal, Linux checks the $PATH variable to see a list of directories to look for the program.
In this guide, we’ll see how to add a directory to the $PATH variable on Linux. This will enable you to call on your program or script from anywhere in the system, without needing to specify the path to where you’ve stored it. Follow along with us as we show how to view the directories in $PATH, and add a directory either temporarily or permanently to the variable.
In this tutorial you will learn:
- How to see currently configured directories in $PATH shell variable
- How to temporarily add directory to $PATH
- How to permanently add directory to $PATH