How To Change Path Variable In Linux
Many operating systems use environmental variables to define various global settings for any part of your operating system or applications to use. The PATH variable is one of these environmental variables which are constantly used without many people realizing it. The variable stores a list of directories where applications (most commonly your shell) should try to look for the program whenever you run a command. You can change the path variable in Linux, follow the simple steps below.
Find out what your current path is configured by running "echo $PATH". A list of directories will be provided such as in the example below:
- uzair@linux:~$ echo $PATH/home/uzair/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games
We can temporarily change this to whatever we would like by running the following command in a bash shell:
- uzair@linux:~$ export PATH=$PATH:/sbin/:/usr/sbin/
Echo the contents of PATH to confirm the changes are reflected in the variable:
- uzair@linux:~$ echo $PATH/home/uzair/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Remember, the above is only temporary and will be lost after a reboot. In order to permanently store this setting, add the same line to your ~/.bashrc file
Changing your PATH variable can potentially cause your operating system to not work properly. Programs frequently refer to this variable to find binary files and if the variable is not configured properly, many programs will stop running. Always test out the setting using the temporary method provided above prior to storing the setting permanently in your ~/.bashrc.