我试图在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

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

其他回答

这只是修改注册表。现有的进程不会使用这些值。如果一个新进程在此更改之后启动,并且不从其父进程继承旧环境,那么它将这样做。

您没有指定如何启动控制台会话。确保这一点的最佳方法是退出命令shell并再次运行它。然后它应该继承更新后的PATH环境变量。

使用gtools中的path。

它以一种直观的方式做事。例如:

pathed /REMOVE "c:\my\folder"
pathed /APPEND "c:\my\folder"

它显示结果,而不需要衍生一个新的cmd!

您不需要任何set或setx命令。只需打开终端,输入:

PATH

这显示了PATH变量的当前值。现在要添加目录吗?简单的类型:

PATH %PATH%;C:\xampp\php

如果出于任何原因你想清除PATH变量(完全没有路径或删除其中的所有路径),输入:

PATH ;

更新

就像Danial Wilson在下面的评论中指出的那样,它只在当前会话中设置路径。要永久地设置路径,请使用setx,但要注意,尽管它会永久地设置路径,但不会在当前会话中设置,因此必须启动一个新的命令行才能查看更改。更多信息在这里。

使用ECHO命令检查环境变量是否存在或查看其值:

echo %YOUR_ENV_VARIABLE%

如何从cmd.exe/Run…打开环境变量窗口对话框

SystemPropertiesAdvanced,点击“环境变量”,没有UAC rundll32 sysdm。cpl,EditEnvironmentVariables直接,可能触发UAC

Windows中的环境变量工具可以直接启动吗?关于服务器故障。

如何从资源管理器打开环境变量窗口

右键点击“这台电脑” 点击“属性” 在弹出窗口的左侧面板上,点击“高级系统设置” 点击“高级”选项卡 点击窗口底部的“环境变量”按钮

您也可以在开始菜单搜索中搜索变量。

参考环境变量窗口的图片:

Windows 10

通过

Windows 7

通过

Windows XP

通过

这次我已经安装了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