Windows 7环境变量不能在path中工作。

时间:2021-09-08 11:45:03

I am trying to set up some path using environment variable. I added an environment variable "MAVEN_HOME" with the value "C:\maven". Then in the path I added "%MAVEN_HOME%\bin;...rest". When I type "echo $MAVEN_HOME%" I get the correct "C:\maven" printed on the screen. But when I type "mvn" which is a batch file in the "bin" directory, it can't find it.

我正在尝试设置一些使用环境变量的路径。我添加了一个环境变量“MAVEN_HOME”,值为“C:\maven”。然后在路径中添加“%MAVEN_HOME%\bin;…rest”。当我键入“echo $MAVEN_HOME%”时,我将在屏幕上显示正确的“C:\maven”。但是当我在“bin”目录中键入“mvn”时,它就找不到它了。

So, I manually added the entire path in PATH. "C:\maven\bin;...rest" and it was able to find "mvn" and execute it.

因此,我手动添加了path中的整个路径。“C:\ maven \ bin,…然后它就能找到“mvn”并执行它。

Could someone help me what I did wrong?

有人能帮我做错了什么吗?

13 个解决方案

#1


46  

I had exactly the same problem, to solve it, you can do one of two things:

我有同样的问题,要解决它,你可以做两件事之一:

  • Put all variables in System Variables instead of User and add the ones you want to PATH
  • 将所有变量放在系统变量中,而不是用户,并添加您想要的路径。

Or

  • Put all variables in User Variables, and create or edit the PATH variables in User Variable, not In System. The Path variables in System don't expand the User Variables.
  • 将所有变量放在用户变量中,并在用户变量中创建或编辑路径变量,而不是在系统中。系统中的路径变量不会扩展用户变量。

If the above are all correct, but the problem is still present, you need to check the system Registry, in HKEY_CURRENT_USER\Environment, to make sure the "PATH" key type is REG_EXPAND_SZ (not REG_SZ).

如果以上都是正确的,但是问题仍然存在,您需要检查系统注册表,在HKEY_CURRENT_USER\环境中,以确保“路径”键类型是REG_EXPAND_SZ(不是REG_SZ)。

#2


67  

Check if there is a space character between the previous path and the next:

检查前一条路径和下一条路径之间是否有空格字符:

Incorrect: c:\path1; c:\Maven\bin\; c:\path2\

错误:c:\ path1;c:\ Maven \ bin \;c:\ path2 \

Correct: c:\path1;c:\Maven\bin\;c:\path2\

正确的:c:\ path1;c:\ Maven \ bin \;c:\ path2 \

#3


26  

My issue turned out to be embarrassingly simple:

我的问题其实很简单:

Restart command prompt and the new variables should update

重新启动命令提示符,新的变量应该更新。

#4


14  

Things like having %PATH% or spaces between items in your path will break it. Be warned.

在路径中有%PATH%或空格之间的空格将会破坏它。被警告。

Yes, windows paths that include spaces will cause errors. For example an application added this to the front of the system %PATH% variable definition:

是的,包含空格的windows路径会导致错误。例如,一个应用程序将此添加到系统%PATH%变量定义的前面:

C:\Program Files (x86)\WebEx\Productivity Tools;C:\Sybase\IQ-16_0\Bin64;

which caused all of the paths in %PATH% to not be set in the cmd window.

这导致%PATH%的所有路径都不能设置在cmd窗口中。

My solution is to demarcate the extended path variable in double quotes where needed:

我的解决方案是在需要的双引号中限定扩展路径变量:

"C:\Program Files (x86)\WebEx\Productivity Tools";C:\Sybase\IQ-16_0\Bin64;

The spaces are therefore ignored and the full path variable is parsed properly.

因此,空间被忽略,完整的路径变量被正确解析。

#5


5  

%M2% and %JAVA_HOME% need to be added to a PATH variable in the USER variables, not the SYSTEM variables.

%M2%和%JAVA_HOME%需要添加到用户变量的路径变量中,而不是系统变量。

#6


5  

If there is any error at all in the PATH windows will silently disregard it. Things like having %PATH% or spaces between items in your path will break it. Be warned

如果在路径窗口中出现任何错误,将会悄无声息地忽略它。在路径中有%PATH%或空格之间的空格将会破坏它。被警告

#7


4  

Also worth making sure you're using the command prompt as an administrator - the system lock on my work machine meant that the standard cmd just reported mvn could not be found when typing mvn --version

同样值得确保您使用的是命令提示符作为管理员——系统锁在我的工作机器上意味着标准cmd刚刚报告mvn在键入mvn -版本时无法找到。

To use click 'start > all programs > accessories', right-click on 'command prompt' and select 'run as administrator'.

要使用点击“开始>所有>附件”,右键点击“命令提示”,选择“作为管理员运行”。

#8


3  

If the PATH value would be too long after your user's PATH variable has been concatenated onto the environment PATH variable, Windows will silently fail to concatenate the user PATH variable.

如果在您的用户的PATH变量被连接到环境路径变量之后,路径值太长,Windows将会悄无声息地连接到用户路径变量。

This can easily happen after new software is installed and adds something to PATH, thereby breaking existing installed software. Windows fail!

这很容易发生在安装了新软件之后,并在PATH中添加了一些东西,从而破坏了现有的安装软件。Windows失败!

The best fix is to edit one of the PATH variables in the Control Panel and remove entries you don't need. Then open a new CMD window and see if all entries are shown in "echo %PATH%".

最好的解决方法是在控制面板中编辑一个路径变量,并删除您不需要的条目。然后打开一个新的CMD窗口,看看是否所有的条目都显示在“echo %PATH%”中。

#9


1  

I had the same problem, I fixed it by removing PATHEXT from user variable. It must only exist in System variable with .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

我有同样的问题,我通过从用户变量中删除PATHEXT来修复它。它必须只存在于系统变量中,即:. .EXE;.BAT;.CMD;.VBS; .JS;.JSE; .WSH;.MSC。

Also remove the variable from user to system and only include that path on user variable

还可以将变量从用户转移到系统,并且只在用户变量上包含该路径。

#10


1  

To address this problem, I have used setx command which try to set user level variables.

为了解决这个问题,我使用setx命令来尝试设置用户级变量。

I used below...

我使用下面……

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_92"

setx PATH %JAVA_HOME%\bin

NOTE: Windows try to append provided variable value to existing variable value. So no need to give extra %PATH%... something like %JAVA_HOME%\bin;%PATH%

注意:Windows试图将提供的变量值添加到现有的变量值中。所以不需要额外的%PATH%…类似% JAVA_HOME % \ bin;% %

#11


0  

Copy the value of path to notepad and check if this corresponds with the echo %path% in terminal window and make changes if needed. Then delete the old path value and paste the notepad value back in. I assume some invisible character entered there by some installation corrupted the path value.

将路径的值复制到记事本,并检查是否与终端窗口中的echo %路径%相对应,并在需要时进行更改。然后删除旧路径值并将notepad值粘贴回去。我假定某个安装中出现的某个看不见的字符损坏了路径值。

#12


0  

Make sure both your System and User paths are set correctly.

确保您的系统和用户路径都设置正确。

#13


0  

I had this problem in Windows 10 and it seemed to be solved after I closed "explorer.exe" in the Task Manager.

我在Windows 10中遇到了这个问题,在我关闭了“浏览器”之后,它似乎得到了解决。在任务管理器中。

#1


46  

I had exactly the same problem, to solve it, you can do one of two things:

我有同样的问题,要解决它,你可以做两件事之一:

  • Put all variables in System Variables instead of User and add the ones you want to PATH
  • 将所有变量放在系统变量中,而不是用户,并添加您想要的路径。

Or

  • Put all variables in User Variables, and create or edit the PATH variables in User Variable, not In System. The Path variables in System don't expand the User Variables.
  • 将所有变量放在用户变量中,并在用户变量中创建或编辑路径变量,而不是在系统中。系统中的路径变量不会扩展用户变量。

If the above are all correct, but the problem is still present, you need to check the system Registry, in HKEY_CURRENT_USER\Environment, to make sure the "PATH" key type is REG_EXPAND_SZ (not REG_SZ).

如果以上都是正确的,但是问题仍然存在,您需要检查系统注册表,在HKEY_CURRENT_USER\环境中,以确保“路径”键类型是REG_EXPAND_SZ(不是REG_SZ)。

#2


67  

Check if there is a space character between the previous path and the next:

检查前一条路径和下一条路径之间是否有空格字符:

Incorrect: c:\path1; c:\Maven\bin\; c:\path2\

错误:c:\ path1;c:\ Maven \ bin \;c:\ path2 \

Correct: c:\path1;c:\Maven\bin\;c:\path2\

正确的:c:\ path1;c:\ Maven \ bin \;c:\ path2 \

#3


26  

My issue turned out to be embarrassingly simple:

我的问题其实很简单:

Restart command prompt and the new variables should update

重新启动命令提示符,新的变量应该更新。

#4


14  

Things like having %PATH% or spaces between items in your path will break it. Be warned.

在路径中有%PATH%或空格之间的空格将会破坏它。被警告。

Yes, windows paths that include spaces will cause errors. For example an application added this to the front of the system %PATH% variable definition:

是的,包含空格的windows路径会导致错误。例如,一个应用程序将此添加到系统%PATH%变量定义的前面:

C:\Program Files (x86)\WebEx\Productivity Tools;C:\Sybase\IQ-16_0\Bin64;

which caused all of the paths in %PATH% to not be set in the cmd window.

这导致%PATH%的所有路径都不能设置在cmd窗口中。

My solution is to demarcate the extended path variable in double quotes where needed:

我的解决方案是在需要的双引号中限定扩展路径变量:

"C:\Program Files (x86)\WebEx\Productivity Tools";C:\Sybase\IQ-16_0\Bin64;

The spaces are therefore ignored and the full path variable is parsed properly.

因此,空间被忽略,完整的路径变量被正确解析。

#5


5  

%M2% and %JAVA_HOME% need to be added to a PATH variable in the USER variables, not the SYSTEM variables.

%M2%和%JAVA_HOME%需要添加到用户变量的路径变量中,而不是系统变量。

#6


5  

If there is any error at all in the PATH windows will silently disregard it. Things like having %PATH% or spaces between items in your path will break it. Be warned

如果在路径窗口中出现任何错误,将会悄无声息地忽略它。在路径中有%PATH%或空格之间的空格将会破坏它。被警告

#7


4  

Also worth making sure you're using the command prompt as an administrator - the system lock on my work machine meant that the standard cmd just reported mvn could not be found when typing mvn --version

同样值得确保您使用的是命令提示符作为管理员——系统锁在我的工作机器上意味着标准cmd刚刚报告mvn在键入mvn -版本时无法找到。

To use click 'start > all programs > accessories', right-click on 'command prompt' and select 'run as administrator'.

要使用点击“开始>所有>附件”,右键点击“命令提示”,选择“作为管理员运行”。

#8


3  

If the PATH value would be too long after your user's PATH variable has been concatenated onto the environment PATH variable, Windows will silently fail to concatenate the user PATH variable.

如果在您的用户的PATH变量被连接到环境路径变量之后,路径值太长,Windows将会悄无声息地连接到用户路径变量。

This can easily happen after new software is installed and adds something to PATH, thereby breaking existing installed software. Windows fail!

这很容易发生在安装了新软件之后,并在PATH中添加了一些东西,从而破坏了现有的安装软件。Windows失败!

The best fix is to edit one of the PATH variables in the Control Panel and remove entries you don't need. Then open a new CMD window and see if all entries are shown in "echo %PATH%".

最好的解决方法是在控制面板中编辑一个路径变量,并删除您不需要的条目。然后打开一个新的CMD窗口,看看是否所有的条目都显示在“echo %PATH%”中。

#9


1  

I had the same problem, I fixed it by removing PATHEXT from user variable. It must only exist in System variable with .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

我有同样的问题,我通过从用户变量中删除PATHEXT来修复它。它必须只存在于系统变量中,即:. .EXE;.BAT;.CMD;.VBS; .JS;.JSE; .WSH;.MSC。

Also remove the variable from user to system and only include that path on user variable

还可以将变量从用户转移到系统,并且只在用户变量上包含该路径。

#10


1  

To address this problem, I have used setx command which try to set user level variables.

为了解决这个问题,我使用setx命令来尝试设置用户级变量。

I used below...

我使用下面……

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_92"

setx PATH %JAVA_HOME%\bin

NOTE: Windows try to append provided variable value to existing variable value. So no need to give extra %PATH%... something like %JAVA_HOME%\bin;%PATH%

注意:Windows试图将提供的变量值添加到现有的变量值中。所以不需要额外的%PATH%…类似% JAVA_HOME % \ bin;% %

#11


0  

Copy the value of path to notepad and check if this corresponds with the echo %path% in terminal window and make changes if needed. Then delete the old path value and paste the notepad value back in. I assume some invisible character entered there by some installation corrupted the path value.

将路径的值复制到记事本,并检查是否与终端窗口中的echo %路径%相对应,并在需要时进行更改。然后删除旧路径值并将notepad值粘贴回去。我假定某个安装中出现的某个看不见的字符损坏了路径值。

#12


0  

Make sure both your System and User paths are set correctly.

确保您的系统和用户路径都设置正确。

#13


0  

I had this problem in Windows 10 and it seemed to be solved after I closed "explorer.exe" in the Task Manager.

我在Windows 10中遇到了这个问题,在我关闭了“浏览器”之后,它似乎得到了解决。在任务管理器中。