Working with the PATH variable on Linux is very easy, this defines where executable programs may be accessed via typing the name of the program and you do not need the full path such as /usr/local/bin/myprog.
Linux will check for executables in the PATH environment only when the full or relative path to the program is supplied. In general, the current directory is not searched unless it is in the PATH. It is possible to include our current directory within the PATH by adding the directory to the PATH variable. This is shown in the following code example:
$ export PATH=$PATH:. |
This is useful for a temporary test when you are wanting to run a program from the current directory.
This command will create a $HOME/bin folder only if it does not already exist.
test -d $HOME/bin || mkdir $HOME/bin |
Very useful when testing executable files.
Below is an example of a full PATH variable on a Linux server.
(base) jason@jason-Lenovo-H50-55:~$ echo $PATH<br />/home/jason/anaconda3/bin:/home/jason/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin |
This is quite complex, but it still makes sense. Each directory is separated by a colon symbol and this makes it easy to edit. Below is a statement that may be used in your ~/.bashrc file.
export PATH="/home/jason/anaconda3/bin:$PATH" |
This will add the /home/jason/anaconda3/bin
folder to the current PATH. This is very easy to use and fast.