How To Set PATH variable on Bash Shell?

How Set PATH Variable on BASH Shell: Hint export command

How Set PATH Variable on BASH Shell?

Have a new executable file/program? Want to execute it just by typing the name of the program instead of full path where the program is located?  The best solution is to add the path to new executable to your list of all search paths. The idea is that every time one types a command the system will look for the command in these search paths first and try to execute it. If it is not found, then you get error.

On a Bash Shell, one can set the path by using “export” command. Here is how to add a path.

export PATH=$PATH:/path/to/newdir

The above export command simply adds the new directory “/path/to/newdir” to existing list of search paths. One can check the current list of paths by typing

echo $PATH

By typing the above echo command before and after adding the path using “export” command, one can make sure if the desired new path is added to the list of paths.

Setting the PATH variable permanently

Typing the export command on the terminal will add the path temporarily just for the current session. And the path will not be in the search path once the session is over.  For example, if you close the terminal, the path will be gone and you have to type the “export” command again.

A better solution that avoids tha hassle of typing evertime you open a terminal is to add the “export” command line to .bashrc.  This will make the path to be automatically added in the search path as you open a terminal/login. The .bashrc file will be in the home directory and can be opened by text editor like vim/pico.