You usually add something to your PATH environment variable by editing the
~/.bashrc file. Which is a text file located in your home directory and easily editable with any text editor.
The PATH environment variable is a string with colons delimiting each path. Your system will read that string left to right and stop when it finds a working path. So imagine that you have two
foo.sh executable scripts. One in ~/.local/share/bin and another in /usr/bin. if your PATH environment variable is set to
~/.local/share/bin:/usr/bin (not the colon delimiter), then when you type
foo.sh in your console it will execute the one in .local/share/bin. To execute the other, you would have to give its full path instead of just the file name.
When you are told to add something to the path, the general procedure is to edit ~/.bashrc. Inside you will want to add a line that will read like one of the two following options:
The first option will prepend your new path to the PATH environment variable, whereas the second option will append to it. Usually the first option is preferable, so you are sure no file inside that new path is masked by other entries in the PATH. The second option is less common, rare even.
But all of the above is meant only if you want to make this change permanent. Sometimes you may only wish for the PATH to be set for the current terminal session. On that case, you would not edit the .bashrc file and instead just issue that same command on the command prompt of your terminal. When you close it, the change to PATH is lost.
Managing your PATH environment variable is one of your tasks as the system administrator of your computer.
But I need to call your attention to the fact it must never start or end with a colon.
<--- THIS IS BAD!
The way the PATH environment variable works, means that if you end it with a colon, you are adding a so-called null directory. The null directory always takes the value of your current directory. This can have security implications. Imagine you moved into a directory you just unpacked from a download and type the ls command to list its files. However there's a malicious ls script file in there. That is what will be executed instead of the normal ls command.
Also note that there are 3 ways to create a null directory entry in the PATH environment variable:
- Start it with a colon:
- End it with a colon:
- Using two adjacent colons: