How to add and change PATH environment variable in linux.

How to add and change PATH environment variable in linux.

Question: How do I add and change PATH environment variable in linux.

Answer: Using export command and .bash_profile file we can add PATH variable temporarily and permanently.

 

How to add and change PATH environment variable in linux.

 

How to view the value of PATH variable ?

We can view the value of PATH variable using command echo $PATH .

echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/rajkumar/bin

What is PATH variable and what is the use of it?

PATH is one of the environment variable. It contains the locations of binary files for the users.
When you execute a command from command line PATH environment variable will give the location of the command.

For example if you execute command pwd PATH variable will tell that pwd binary file is located at /bin/pwd execute it. This is how every command works for users.

How to add, set and change PATH environment variable.

Temporary method to add /sbin to PATH environment variable.

su – username
export PATH=$PATH:/sbin

If you logout or open another session this PATH variable value will not be available.

Permanent method to add /sbin to PATH environment variable.

su – username
echo export PATH=$PATH:/sbin >> $HOME/.bash_profile

If you add PATH variable value in .bash_profile even if you logout or open another session this PATH variable valu will be available.

Permanent method to add /sbin to PATH environment variable to all users in the linux machine.

echo export PATH=$PATH:/sbin >> /etc/profile

If you add the PATH environment variable value to /etc/profile then it will be available to all users.

How to add and change PATH environment variable in linux

 




Leave a Reply

Your email address will not be published. Required fields are marked *