Adding a directory to the PATH environment variable in Windows
Option 1
After you change PATH
with the GUI, close and re-open the console window.
This works because only programs started after the change will see the new PATH
.
Option 2
Execute this command in the command window you have open:
set PATH=%PATH%;C:\your\path\here\
This command appends C:\your\path\here\
to the current PATH
.
Breaking it down:
set
– A command that changes cmd's environment variables only for the current cmd session; other programs and the system are unaffected.PATH=
– Signifies thatPATH
is the environment variable to be temporarily changed.%PATH%;C:\your\path\here\
– The%PATH%
part expands to the current value ofPATH
, and;C:\your\path\here\
is then concatenated to it. This becomes the newPATH
.
WARNING: This solution may be destructive to your PATH, and the stability of your system. As a side effect, it will merge your user and system PATH, and truncate PATH to 1024 characters. The effect of this command is irreversible. Make a backup of PATH first. See the comments for more information.
Don't blindly copy-and-paste this. Use with caution.
You can permanently add a path to PATH
with the setx
command:
setx /M path "%path%;C:\your\path\here\"
Remove the /M
flag if you want to set the user PATH
instead of the system PATH
.
Notes:
- The
setx
command is only available in Windows 7 and later. You should run this command from an elevated command prompt.
If you only want to change it for the current session, use set.
This only modifies the registry. An existing process won't use these values. A new process will do so if it is started after this change and doesn't inherit the old environment from its parent.
You didn't specify how you started the console session. The best way to ensure this is to exit the command shell and run it again. It should then inherit the updated PATH environment variable.