Set a Path in Linux

In linux you may want to include custom compiled tools into your path variable so that you do not need to explicitly specify the source path with each reference. To do this you will need to take advantage of your shell’s environment variables and config files. With bash for example, which is the default shell for most linux distributions, you will need to modify the ~/.bashrc file. This file will be sourced upon each login. To add something custom to your path you will need to:

vi ~/.bashrc

Then add


export PATH=/path/to/new/tool/bin:$PATH

This will re-export your PATH variable to include the location of your new tool’s bin directory, in addition to the default path that was set previously. It is important to add the $PATH at the end so that what has already been sourced will be included. If you don’t you will find that you don’t have any commands at all, like ls. Also, be sure to add a colon between each location you specify.

It is always a good idea to have two terminals open when doing stuff like this, incase you have a typo or something goes wrong. You have a second functioning terminal to work with in order to correct any problems.

Be the first to comment

Leave a Reply