Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a directory to the PATH environment variable in Windows

I am trying to add C:\xampp\php 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:

C:\>path 

it doesn't show the new C:\xampp\php directory:

PATH=D:\Program Files\Autodesk\Maya2008\bin;C:\Ruby192\bin;C:\WINDOWS\system32;C:\WINDOWS; C:\WINDOWS\System32\Wbem;C:\PROGRA~1\DISKEE~2\DISKEE~1\;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\QuickTime\QTSystem\;D:\Program Files\TortoiseSVN\bin ;D:\Program Files\Bazaar;C:\Program Files\Android\android-sdk\tools;D:\Program Files\ Microsoft Visual Studio\Common\Tools\WinNT;D:\Program Files\Microsoft Visual Studio\Common \MSDev98\Bin;D:\Program Files\Microsoft Visual Studio\Common\Tools;D:\Program Files\ Microsoft Visual Studio\VC98\bin 

I have two questions:

  1. Why did this happen? Is there something I did wrong?
  2. Also, how do I add directories to my PATH variable using the console (and programmatically, with a batch file)?
like image 250
Netorica Avatar asked Mar 03 '12 12:03

Netorica


People also ask

What does adding directory to PATH mean?

Adding a directory to your PATH expands the # of directories that are searched when, from any directory, you enter a command in the shell.

Should I add directory to PATH?

Adding directories to your PATH will allow you to run executables or scripts in those directories, effectively adding commands to your system shell's dictionary of commands to recognize.

How do I create a directory PATH?

Moving into folders To write a path that moves into a folder we specify the folder name, followed by a forward slash, then the file name.


2 Answers

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 that PATH is the environment variable to be temporarily changed.
  • %PATH%;C:\your\path\here\ – The %PATH% part expands to the current value of PATH, and ;C:\your\path\here\ is then concatenated to it. This becomes the new PATH.
like image 104
JimR Avatar answered Oct 07 '22 13:10

JimR


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.

like image 43
Nafscript Avatar answered Oct 07 '22 13:10

Nafscript