Linux Commands

How to Export “PATH” environment variable in Linux

Exporting the “PATH” environment variable is the way to optimize your system’s efficiency. It provides you with seamless access to the executable files. The “PATH” variable holds the location of directories where the executable files reside in your Linux system.

When you enter a command in the terminal to access the utility, your system checks the path of the specific utility. You can also check and save the path through the “export” command. So, if you do not know how to export the path, don’t worry because this quick guide has a simple way to export “PATH” in Linux.

How to Export “PATH” in Linux

Whenever you enter a command, the terminal will search for it in the locations that are saved in “PATH”. Though it already holds numerous values, you can always add new ones using the “export” command.

First, copy the directory path that you want to add to “PATH”. For instance, if it is in the “Downloads” directory, the path will be:

cd ~/downloads/

 
Open the terminal and access your shell’s configuration file using a text editor. You can use one of the following commands:

For Bash: nano ~/.bashrc

For Zsh: nano ~/.zshrc

At the end of the file, enter it in the following syntax:

export PATH=$PATH:/New_Path

 

    • The “$PATH” references the current value of the “PATH” variable.
    • The “PATH” variable has the list of directories separated by a colon “:,” which lets the system distinguish the different paths. As we add a new path, the colon helps us to maintain that functionality.
    • Replace “/New_Path” with the path that you copied in the first step.

Now, close the file. As we use the nano editor, use these three steps to exit it: “CTRL + X”, press “Y”, and then press “Enter”.

Please note that to make these changes take effect, you must either restart the terminal/shell or enter the following command:

source ~/.bashrc

 

Replace the “bashrc” file with your respective configuration file in the previous code. Finally, this is all for the process. To demonstrate it, let’s export the path of the “Downloads” directory and verify it by running the following command:

cd ~/Downloads
echo $PATH

 

As the previous image explains, we successfully exported a new PATH, i.e., “New_Path”.

Conclusion

Exporting PATH is an essential command that you should know to keep your system optimized. Exporting means adding a value to a variable which, in this case, is the PATH environment variable. Here, we explained the easy way to export PATH in Linux. The process is simple: copy the file path, edit the shell’s configuration file, and enter the “export” command. Moreover, even a point(.) can cause an error despite the simplicity. Hence, you must correctly enter the mentioned commands.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.