The “export PATH=something:$PATH” command modifies the PATH environment variable of the current system. The “PATH” variable contains the list of directories that the operating system searches for specific executable files. It has significance when users want to run an installed program from the command line without having to specify the full path to its executable file.
This article will explain the “export PATH=something:$PATH” command along with practical implementation in Linux.
- What Does “export PATH=something:$PATH” Mean in Linux?
- How Does the “export PATH=something:$PATH” Work in Linux
What Does “export PATH=something:$PATH” Mean in Linux?
The “export” keyword is utilized to set an environment variable in the active shell session. It provides all subprocesses and programs which are initiated from the current shell.
In this case, “PATH” is being set to a new value that consists of two parts: “something” and “$PATH”.
- The “something” part of the command is a directory that the user needs to add to the PATH environment variable. This can be the full path to a directory, or just a directory name if it is located in one of the directories already listed in the PATH environment variable.
- The “$PATH” part of the command is a reference to the current value of the PATH environment variable. The “$” symbol is used to access the value of the PATH variable. By including $PATH at the end of the new value for PATH, you can append the new directory to the existing PATH environment variable, rather than replacing it entirely.
Working of “export PATH=something:$PATH” Command in Linux
The “export PATH=something:$PATH” command allows the system to search for executables in the new directory. Here are a few examples of using the above-mentioned command in Linux:
Example 1: Adding a Directory to PATH
To add a directory to the PATH, users can set the path by specifying the address. For instance, the “/usr/local/bin” directory path is added to the “PATH” variable:
$ export PATH=/usr/local/bin:$PATH
The output confirms that the “/usr/local/bin” directory has been added to the “PATH” environment variable.
Example 2: Adding Multiple Directories to PATH
To add multiple directories to the “PATH” variable, users are required to specify the directories path. For instance, the “$HOME/bin” and “/usr/local/sbin” directories are added to the PATH environment variable. The “$HOME” variable represents the home directory of the existing user:
$ export PATH=$HOME/bin:/usr/local/sbin:$PATH
The output confirms that the “HOME/bin and /usr/local/sbin” directories have been added to the PATH environment variable.
Conclusion
The “export PATH=something:$PATH” command changes the “PATH” environment variable of the current system by specifying the path of the directory in the “something” variable. This command allows the system to search for executables in a particular directory. Users can also add multiple directories to PATH. This article has briefly explained the “export PATH=something:$PATH” command along with possible examples in Linux.