How to Change PATH Variable on Linux: 5 Steps (with Pictures)

Table of contents:

How to Change PATH Variable on Linux: 5 Steps (with Pictures)
How to Change PATH Variable on Linux: 5 Steps (with Pictures)

Video: How to Change PATH Variable on Linux: 5 Steps (with Pictures)

Video: How to Change PATH Variable on Linux: 5 Steps (with Pictures)
Video: How to login as root in Linux - Ubuntu | Linux in a Minute 2024, May
Anonim

Operating systems generally use environment variables to define various global settings that affect parts of the system, or to manage applications. The PATH variable is one of the environment variables, and is often used without the user's knowledge. This variable holds a list of directories that will be used by applications (especially shells) to search for commands.

Step

Change the Path Variable in Linux Step 1
Change the Path Variable in Linux Step 1

Step 1. Know the contents of the PATH variable by entering the command "echo $PATH" in the shell window

You will see a list of directories as in the following example:

  • uzair@linux:~$ echo $PATH/home/uzair/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games
  • Note: the directory display in the $PATH variable is separated by ":".
Change the Path Variable in Linux Step 2
Change the Path Variable in Linux Step 2

Step 2. Add directory ":

/sbin" and ":/usr/sbin" temporarily to the PATH list with the following command:

uzair@linux:~$ export PATH=$PATH:/sbin/:/usr/sbin/

Change the Path Variable in Linux Step 3
Change the Path Variable in Linux Step 3

Step 3. Display the contents of the PATH variable to confirm that the change has taken place

  • uzair@linux:~$ echo $PATH/home/uzair/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
  • Keep in mind that the above changes are only temporary and will disappear when the computer restarts.
Change the Path Variable in Linux Step 4
Change the Path Variable in Linux Step 4

Step 4. Try running the app which is in the new PATH to make sure your changes are not causing any problems

Change the Path Variable in Linux Step 5
Change the Path Variable in Linux Step 5

Step 5. Change the PATH variable permanently by inserting the same line into the ~/.bashrc file

Recommended: