What is PATH?
If you’ve edited anything from a terminal or command line then you’ve used your system Path. A system’s path is stored in the PATH environment variable, which references paths to directories containing executable files (programs). Adding a directory to your path allows you to run the executables in that directory from the command by typing the name of the executable, without having to reference the executable’s full path. When working with Unix-based systems you can permanently add a directory to your Path by editing your .bashrc or .bash_profile files. Windows doesn’t have either of these files. Luckily there are still a few options if you’re looking to edit your Path from the Windows Command Prompt.
Edit Windows PATH for Current CMD Only
You can update your Windows Path from the Command Prompt by locally setting PATH to a new value.
The above command adds the Program File directory named Directory_With_Executable to your path. This allows you to call any executables in this Directory_With_Executable from your current Command Prompt without having to enter the full executable path.
Note that the set command does not permanently alter Windows environment variables. Therefore, closing and reopening your Command Prompt will restore PATH to its previous value.
Permanently Edit Windows PATH from CMD
You can permanently alter your Windows Path from the Command Prompt by editing the system registry value for the Path environment variable. The new Path variable will take effect when you close and reopen the Command Prompt, but not in the current Command Prompt.
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_SZ /d "%PATH%;%PROGRAMFILES%\%PROGRAMFILES%\Directory_With_Executable"
HKLM\SYSTEM indicates that you’re editing a registry key on your local system.
/v indicates the name of the registry value you want to alter. The example above alters an environment key, which corresponds to a system environment variable (in this case, the %PATH% variable).
/t indicates the data type of the registry key.
/d indicates the data to assign to the registry key value. The example above permanently overwrites the Path value to the current Path value plus a directory from Program Files to the system Path value.
/f forces the command to overwrite the preexisting key value. Omitting /f will prompt you for a response before overwriting any preexisting key values.