我试图在Windows中添加C:\xampp\php到我的系统PATH环境变量。
我已经使用环境变量对话框添加了它。
但当我在控制台输入:
C:\>path
它不会显示新的C:\xampp\php目录:
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
我有两个问题:
为什么会发生这种情况?我做错什么了吗?
另外,如何使用控制台(并以编程方式,使用批处理文件)向PATH变量添加目录?
选项1
在使用GUI更改PATH之后,关闭并重新打开控制台窗口。
这是可行的,因为只有在更改之后启动的程序才能看到新的PATH。
选项2
此选项仅影响当前shell会话,而不会影响整个系统。在已打开的命令窗口中执行以下命令:
set PATH=%PATH%;C:\your\path\here\
该命令将C:\your\path\here\追加到当前路径。如果路径包含空格,则不需要包含引号。
分解一下:
set -仅为当前cmd会话更改cmd的环境变量的命令;其他程序和系统不受影响。
PATH= -表示PATH是要临时更改的环境变量。
%PATH%;C:\your\ PATH \here\ - %PATH%部分扩展为PATH的当前值,然后;C:\your\ PATH \here\被连接到它。这将成为新的PATH。
在Windows 10 LTSB上查看上述建议,并浏览一下“帮助”概要(可以在输入'command /?’),让我得出结论,PATH命令只改变当前会话的系统环境变量PATH值,但重新启动后,所有值重置为默认值-就像使用PATH命令之前一样。
另一方面,使用具有管理权限的SETX命令要强大得多。它会永久地改变这些值(或者至少在下次使用此命令或在下一次手动GUI操作这些值之前……).
最适合我的SETX语法用法:
SETX PATH "%PATH%;C:\path\to\where\the\command\resides"
这里应该避免使用等号“=”,不要担心空格!对于包含空格的路径,不需要再插入任何引号——分隔符号';'就可以了。
SETX后面的PATH关键字定义了在系统环境变量可能的值中应该改变哪一组值,而引号内的%PATH%(被百分号包围的单词PATH)告诉操作系统保持现有PATH值不变,并将下面的路径(跟随分隔符号';'的路径)添加到现有值中。
在Windows 10上,我能够搜索set path环境变量,并得到这些指令:
From the desktop, right-click the very bottom-left corner of the screen to get the Power User Task Menu.
From the Power User Task Menu, click System.
In the Settings window, scroll down to the Related settings section and click the System info link.
In the System window, click the Advanced system settings link in the left navigation panel.
In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.
In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below:
C:\程序文件;C:\Winnt;C:\Winnt\System32
我第一次搜索它时,它立即弹出了系统属性窗口。之后,我找到了上面的说明。