Not satisfied by the Answer? Still have doubts?
Ask Question

Adding a directory to the PATH environment variable in Windows

I am trying to join C:xamppphp to my system PATH environment variable in Windows.

I have already added it using the Environment Variables dialog box.

But when I type into my console:

PATH=D:Program FilesAutodeskMaya2008bin;C:Ruby192bin;C:WINDOWSsystem32;C:WINDOWS;
C:WINDOWSSystem32Wbem;C:PROGRA~1DISKEE~2DISKEE~1;c:Program FilesMicrosoft SQL
Server90Toolsbinn;C:Program FilesQuickTimeQTSystem;D:Program FilesTortoiseSVNbin
;D:Program FilesBazaar;C:Program FilesAndroidandroid-sdktools;D:Program Files
Microsoft Visual StudioCommonToolsWinNT;D:Program FilesMicrosoft Visual StudioCommon
MSDev98Bin;D:Program FilesMicrosoft Visual StudioCommonTools;D:Program Files
Microsoft Visual StudioVC98bin

I have two questions:

Why did this happen? Is there something I did wrong?
Also, how do I add directories to my PATH variable using the console (and programmatically, with a batch file)?
path command-line windows

3 Answers

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.
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:yourpathhere

This command appends C:yourpathhere 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 that PATH is the environment variable to be temporarily changed.
%PATH%;C:yourpathhere – The %PATH% part expands to the current value of PATH, and ;C:yourpathhere is then concatenated to it. This becomes the new PATH.
Handy if you are already in the directory you want to add to PATH:

set PATH=%PATH%;%CD%

It works with the standard Windows cmd, but not in PowerShell.

For PowerShell, the %CD% equivalent is [System.Environment]::CurrentDirectory.

Login / Signup to Answer the Question.

  • Be descriptive with your answer, and try to avoid copy-pasting external links, instead guide the user who has asked the question, where can they find the detailed answer.
  • You cannot share any URL in answer.
  • To make a text bold, surround the text with single asterisk, for example *bold text*
  • To format a text like code, surround the text within double asterisk, for example **code**
  • To add a multiline piece of code, surround the whole code within triple asterisk, for example *** multiline code ***
  • Please verify before submitting the answer.