Adding a directory to the $PATH on Linux permanently is easy to do. Although many Linux user don’t know how to do that. That’s why in this article I will show you guys how to do that.
First of all, we have to know that why we have to add a directory to the $PATH. $PATH is environment variable and when we add a directory to the $PATH, we are actually telling the shell something. We told the shell to look for an executable file in that directory. The main reason of adding a path to the $PATH is that, each time we don’t have to put the full file location to execute any file.
So how to add a directory to the $PATH? Let me show you that.
Permanently set $PATH on Linux
To add something to the $PATH just follow my steps and you’ll be good to go.
1. Adding it to ~/.profile or ~/.bashrc file
First you have to add the bath to your ~/.profile or ~/.bashrc file. To do that use this command and you’ll be good to go.
2. Symlink to binaries
You may also need to symlink to binaries. But it depends on what you are going to do.
To do that use this command:
cd /usr/bin && sudo ln -s /path/to/binary binary-name
3. Update the path
Finally you just need to update the path and you’re good to go. To update the path use this command: