Viewing PATH
Suppose you want to install programs in a different location on your system and run the program without mentioning their location. A simple way to accomplish this is to change your $PATH variable. Write out the following command to view what exists currently in your $PATH:
Most likely, you will see the various directories separated by colons. Now let’s check out the methods of changing the $PATH in the Linux terminal.
Method 1: Temporarily changing $PATH in terminal
For instance, you have a directory named “bin” in your Home directory, and you want this location to be where you save all of your shell scripts. You can easily make these changes by modifying the $PATH variable. The modified $PATH variable will be exported to the shell child process environments using the “export” command. In addition, after modifying the $PATH, you can now execute any shell script by only specifying the executable script name rather than typing the entire path of the file. These settings will change the $PATH, but temporarily.
“echo” the $PATH variable to confirm the changes we made into the path of the Linux terminal.
Method 2: Permanently changing $PATH in terminal
To change the $PATH permanently, you must define the $PATH variable configuration files. When you start a new session in most Linux versions, environment variables are read from the shell configuration files customized for each user. If you are a bash user, utilize the “~./bashrc” file for changing $PATH. First, open the “~./bashrc” file in the text editor by typing the following command.
Write out the below-given lines into this configuration file.
Execute the source command to save the file with the change we made into the $PATH. This command will also load the new path in the current session of the Linux terminal.
Again, print out the value of $PATH for the confirmation of the changes.
The output declares that the $PATH is successfully changed in the Linux terminal.
Conclusion
Changing $PATH in the terminal comprises a simple yet straightforward procedure. This allows any Linux user to run scripts and commands from a non-standard location without specifying the entire path of those executable shell scripts. This article has provided you two different methods for changing $PATH in the Linux terminal.