我试图在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变量添加目录?


当前回答

在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

我第一次搜索它时,它立即弹出了系统属性窗口。之后,我找到了上面的说明。

其他回答

警告:此解决方案可能会破坏您的PATH和系统的稳定性。作为副作用,它将合并用户和系统PATH,并将PATH截断为1024个字符。此命令的效果是不可逆转的。首先备份PATH。有关更多信息,请参阅评论。 不要盲目地复制粘贴。请谨慎使用。

你可以使用setx命令永久地添加一个路径到path:

setx /M path "%path%;C:\your\path\here\"

如果您想设置用户PATH而不是系统PATH,请删除/M标志。

注:

setx命令仅适用于Windows 7及以上版本。 您应该从提升的命令提示符运行此命令。 如果您只想为当前会话更改它,请使用set。

下面的解决方案非常有效。

在你的Windows终端上试试下面的命令。

setx PATH "C:\myfolder;%PATH%"

SUCCESS:保存了指定的值。

你可以参考更多在这里。

除了这些答案,如果你想要一个很好的GUI工具来编辑你的Windows环境变量,你可以使用快速环境编辑器。

试一试!它使用起来很安全,而且很棒!

这次我已经安装了PHP。我提取php-7***.zip到C:\php</ I > 备份我当前的PATH环境变量:运行cmd,执行命令:PATH >C:\ PATH -backup.txt 获取当前路径值到C:\path.txt文件(同样的方法) 修改path.txt(当然,我的路径长度超过1024个字符,Windows运行了几年)

我已经在那里删除了重复的路径,比如'C:\Windows;或C:\Windows\ System32系统;或C:\Windows\System32\ Wbem;-我有两次。 也可以删除已卸载的程序路径。例如:C:\Program Files\ NonExistSoftware; 这样,我的路径字符串长度< 1024:)))) 在路径字符串的末尾,添加;C:\php\ 复制路径值只到缓冲区与框架双引号!示例:"C:\Windows;****;C:\php"不应该有PATH= !!

以管理员身份打开Windows PowerShell(例如Win + X)。 运行命令: 这里你应该插入字符串从缓冲区(新的路径值)" 重新运行您的终端(我使用“Far Manager”)并检查: php - v

在Windows上的Bash shell中使用这些命令将一个新位置附加到PATH变量

PATH=$PATH:/path/to/mydir

或者在这个位置前面加上前缀

PATH=/path/to/mydir:$PATH

例如,在你的情况下,做

PATH=$PATH:C:\xampp\php

您可以回显$PATH以查看shell中的PATH变量。