Adding a directory to the PATH environment variable in Windows
You don't need any set
or setx
command. Simply open the terminal and type:
PATH
This shows the current value of PATH variable. Now you want to add directory to it? Simply type:
PATH %PATH%;C:\xampp\php
If for any reason you want to clear the PATH variable (no paths at all or delete all paths in it), type:
PATH ;
Update
Like Danial Wilson noted in comment below, it sets the path only in the current session. To set the path permanently, use setx
but be aware, although that sets the path permanently, but not in the current session, so you have to start a new command line to see the changes. More information is here.
To check if an environmental variable exist or see its value, use the ECHO command:
echo %YOUR_ENV_VARIABLE%
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.
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.
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
This option only affects your current shell session, not the whole system. 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
. If your path includes spaces, you do NOT need to include quote marks.
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
.