Bootstrap FreeKB - Linux Fundamentals - $PATH variable
Linux Fundamentals - $PATH variable

Updated:   |  Linux Fundamentals articles

$PATH is a default Linux variable that contains directories that will be searched for command line interfaces (CLIs).

echo or printf can be used to display the current directories in the $PATH variable.

echo $PATH

 

Which should return something like this.

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

 

For example, the which command can be used to determine if a Command Line Interface (CLI) exists in $PATH. For example, which can be used to determine if the java CLI exists in $PATH.

which java

 

If the java CLI does exist in $PATH, something like this should be returned, meaning that the java CLI is located at /usr/bin/java. In this example, since /usr/bin is one of the directories in $PATH, which was able to determine that the java CLI exists at /usr/bin/java.

/usr/bin/java

 

Directories can temporarily be appended to the PATH variable like this.

export PATH=$PATH:/opt/foo:/usr/bar

 

Better yet, PATH can be defined in your /home/username/.bash_profile file, so that every time you sign into the system, your PATH will contain the directories defined in your .bash_profile file.

PATH=$PATH:/home/john.doe/.local/bin:/home/john.doe/bin
export PATH

 

You would then want to log out of the system, log back in, and echo or printf should now contain the additional directories.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter aca1fa in the box below so that we can be sure you are a human.