Editing Environment Path Variable
In some installation and management tasks, you need to edit the path environment variable to specify the directories in which binary programs are stored so that the programs can be invoked by a command.
Getting the PATH variable on Linux
In Linux, the path variable is a string with absolute paths of directories, and these paths are separated with a colon (:
). You can see the path variable ($PATH
) by using the echo command:
Before editing the Path variable, copy the current value and save it in a different system.
Editing the PATH variable on Linux
In Linux, you can append a directory path to the path variable by using the export command. The following example appends the colon (:
) separator and the directory path, /opt/bin
, to the current path variable ($PATH
):
$ export PATH="$PATH:/opt/bin"
If you run this command in the shell, the shell updates the path variable within the current session only.
To set this new path variable permanently, add this export command in the startup file of the shell. To check what kind of shell you are using, run the following command:
The example output indicates that you are using Bash. In this case, add the export command in /root/.bashrc
:
$ sudo nano /root/.bashrc
To load the startup file, restart the system or use the source command in the current session:
$ sudo source /root/.bashrc
Getting the Path variable on Microsoft Windows
In Microsoft Windows, the path variable is a string with absolute paths of folders too, and these paths are separated with a semi-colon (;
). You can see the path variable by using the following command on Microsoft Windows PowerShell or Microsoft PowerShell:
Before editing the Path variable, copy the current value and save it in a different system.
Editing the Path variable on Microsoft Windows
In Microsoft Windows, take the following steps to edit the Path environment variable:
In Microsoft Windows, open Control Panel.
Go to System and Security > System to open the System Settings window.
In the System Settings window, click Advanced system settings to open the System Properties dialog.
In the System Properties dialog, open the Advanced tab and click Environment Variables... to open the Environment Variables dialog.
In the Environment Variables dialog, click Path in the list of user variables and click Edit...
In the Edit environment variable dialog for the Path variable, you can add, edit, or delete values.
Last updated