Adding a Folder to the PATH List
In general, it is a good idea to make yourself a new directory, add all your executable script files there, and then add that directory to the PATH locations. This is especially useful if you do not already have a folder named bin inside ~/.local directory.
First, make the folder which you need to add to PATH.
- If the folder already exists, then you can skip this step.
- If it doesn’t exist, then you can make it – either using the terminal command mkdir, or using the GUI.
Second, not the path address of the folder. For instance, if the folder is named mypath and it is inside my home directory, then the location will be
/home/user/mypath
Third, open the .bashrc file in a preferred editor. This is a hidden file inside the home folder. You can see it in your GUI by using Ctrl+H to view hidden files, and then double-click on it. Alternatively, inside a terminal, you can use nano, vi, or vim to open the file with a command:
nano ~/.bashrc
Remember, this is a very important system file. Do not mess with this file unless you know what you are doing! Simply add one line at the end of the file, with this content:
export PATH="$PATH:<your-directory-path>"
For instance, if the directory is /home/user/mypath, then we can use the command:
export PATH="$PATH:/home/user/mypath"
The last step is to close and reopen your terminal. All terminals you open from this point on will treat executable files inside mypath as commands. If you do not want to close and reopen your terminal, simply run the command
. ~/.bashrc
and it will update itself and your executable file with a Shebang will be available as a command.
Remember: Your script must have a correct Shebang for it to become a command!
Using Shebang in Linux
Imagine you’re working on a Linux computer and have a recipe with instructions written in different languages. But your computer only understands English! That’s where the shebang comes in. It’s like a tiny label at the beginning of the recipe that tells your computer which “translator” to use for each language. This magic symbol, #!
, followed by the interpreter’s path, is the key to understanding and running all sorts of scripts on your system.