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:

$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/dpxadmin/.local/bin:...

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:

$ echo $0
-bash

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:

PS> Write-Output $ENV:Path
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;...

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:

  1. In Microsoft Windows, open Control Panel.

  2. Go to System and Security > System to open the System Settings window.

  3. In the System Settings window, click Advanced system settings to open the System Properties dialog.

  4. In the System Properties dialog, open the Advanced tab and click Environment Variables... to open the Environment Variables dialog.

  5. In the Environment Variables dialog, click Path in the list of user variables and click Edit...

  6. In the Edit environment variable dialog for the Path variable, you can add, edit, or delete values.

Last updated