Windows 10 上的环境变量太大
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34491244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Environment Variable is too large on Windows 10
提问by olammy
I know this is strange and I have spent almost 3 days searching for the solution online without getting a useful one. So I have decided to come here.
我知道这很奇怪,我花了将近 3 天的时间在网上搜索解决方案,但没有找到有用的解决方案。所以我决定来这里。
I have recently upgraded to Windows 10 from Windows 8.1.
我最近从 Windows 8.1 升级到了 Windows 10。
Now I wanted to set an Environment variable for my new installation of Apache Maven.
现在我想为我新安装的 Apache Maven 设置一个环境变量。
Each time I created the user variable, things are fine. However, I also need to create the system variable where I will need to append the bin directory to the variable that I aready create in the user variable to be "path".
每次我创建用户变量时,一切都很好。但是,我还需要创建系统变量,我需要将 bin 目录附加到我在用户变量中创建的变量中作为“路径”。
Now, each time I do this I get an erron that says "This Environment Variable is too large. As a result of this, I am unable to create the path.
现在,每次我这样做时,我都会收到一个错误消息,提示“此环境变量太大。因此,我无法创建路径。
I have attached image of this error.
我附上了这个错误的图片。
I will appreciate this if anyone can assist me to solve this problem.
如果有人能帮助我解决这个问题,我将不胜感激。
回答by Swapnil Kamat
When PATH variable gets overloaded with too many values it reaches a point where you cannot add values anymore. Trying the following should solve your problem.
当 PATH 变量因过多的值而过载时,它会达到无法再添加值的程度。尝试以下方法应该可以解决您的问题。
Solution 1:
解决方案1:
- Create a new system variable say 'NEWPATH'
- Assign the bin directory location to 'NEWPATH'
- Now append '; %NEWPATH%' to the PATH variable
- 创建一个新的系统变量说“NEWPATH”
- 将 bin 目录位置分配给“NEWPATH”
- 现在附加 ' ; %NEWPATH%' 到 PATH 变量
If this still doesn't work then try to copy some part of PATH variable already existing values to the 'NEWPATH' and then append the 'NEWPATH'
如果这仍然不起作用,请尝试将 PATH 变量已经存在的值的某些部分复制到“NEWPATH”,然后附加“NEWPATH”
Solution 2:
解决方案2:
Check the value of PATH variable if you can group and shorten the paths. For example,
如果可以对路径进行分组和缩短,请检查 PATH 变量的值。例如,
C:\Program Files\Microsoft SQL Server\102\Tools\Binn\;C:\Program Files\Microsoft SQL Server\102\DTS\Bin\;
C:\Program Files\Microsoft SQL Server\102\Tools\Binn\;C:\Program Files\Microsoft SQL Server\102\DTS\Bin\;
can be combined to
可以组合成
C:\Program Files\Microsoft SQL Server;
C:\Program Files\Microsoft SQL Server;
In this way you can build more space into your fixed length PATH variable and finally adjust your bin directory location into PATH.
通过这种方式,您可以在固定长度的 PATH 变量中构建更多空间,并最终将 bin 目录位置调整到 PATH 中。
Hope this helps you!
希望这对你有帮助!
回答by Shital Shah
There are few ways to clean up your path variable. The easiest is to use Rapid Environment Editor. This free utility will,
有几种方法可以清理您的路径变量。最简单的方法是使用Rapid Environment Editor。这个免费的实用程序将,
- Remove the duplicate paths (right click > Cleanup Paths)
- Remove non-existent folders (shown in red which you need to manually delete)
- Replace long paths with short paths (right click > long to short path).
- 删除重复的路径(右键单击 > 清理路径)
- 删除不存在的文件夹(红色显示需要手动删除)
- 用短路径替换长路径(右键单击 > 长到短路径)。
I do above steps in order and use 3rd step only for longest paths until Path variable size is in control again.
我按顺序执行上述步骤,仅对最长路径使用第 3 步,直到 Path 变量大小再次受到控制。
If you want to go more advanced, here's little C# toolthat you can modify to whatever other logic you want to implement.
如果你想要更高级,这里有一个小的 C# 工具,你可以修改为你想要实现的任何其他逻辑。
回答by Sifou13
Another solution or more a workaround to bypass the Environment PATH variable length limit is to manage your path (add, remove or update) using a PowerShell script;
绕过环境路径变量长度限制的另一种解决方案或更多解决方法是使用 PowerShell 脚本管理您的路径(添加、删除或更新);
1) Capture the current PATH variable by clicking "Edit Text" (see above screenshot) and copy it to your clipboard and save it in a text file as a backup too to avoid bad surprises. This is not mandatory but will allow you to recover should something go wrong.
1) 通过单击“编辑文本”(见上面的屏幕截图)捕获当前的 PATH 变量并将其复制到剪贴板并将其保存在文本文件中作为备份,以避免出现意外。这不是强制性的,但可以让您在出现问题时恢复。
2) Now that it is backed up, add the following to a new PowerShell (.ps1) file (amending the first line below with the folder path(s) you want to add (the part after the + sign):
2) 现在它已备份,将以下内容添加到新的 PowerShell (.ps1) 文件中(使用您要添加的文件夹路径(+ 号后面的部分)修改下面的第一行:
$newPath = $env:Path + '; C:\Users\....\FirstFolderToAddToPath; C:\Users\....\SecondFolderToAddToPath;'
[Environment]::SetEnvironmentVariable("Path", $newPath, "Machine")
$env:Path = $newPath
This is how I managed to get my (long) PATH variable back after playing with the Windows 10 UI, being caught by the length limitation and loosing most of my path. I hope it helps.
这就是我在玩 Windows 10 UI 后设法恢复我的(长)PATH 变量的方式,被长度限制所捕获并丢失了我的大部分路径。我希望它有帮助。
回答by alexlomba87
In addition to the answer of Swapnil, note that you can modify the maximum length of the Path variable - which is otherwise limited to 2048 characters (while a single path has an historical limit of 206 characters).
In Windows 10, you achieve this by setting the LongPathsEnabled
registry key to 1, which can be found here:
除了 Swapnil 的回答之外,请注意您可以修改 Path 变量的最大长度 - 否则限制为 2048 个字符(而单个路径的历史限制为 206 个字符)。在 Windows 10 中,您可以通过将LongPathsEnabled
注册表项设置为 1 来实现此目的,可在此处找到:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
To access the registry editor: Windows Key+R
, type Regedit
.
要访问注册表编辑器:Windows Key+R
,请键入Regedit
。
Source: https://superuser.com/a/1119980
来源:https: //superuser.com/a/1119980
Also take a look at this SuperUser answer: https://superuser.com/a/1119980/327009
也看看这个超级用户的回答:https: //superuser.com/a/1119980/327009
Addressing the comment below: the error "Environment variable is too large" is related to the whole variable, not the single path currently being added.
解决下面的评论:错误“环境变量太大”与整个变量有关,而不是当前添加的单个路径。
回答by Bryan
Late answer but I was looking for something similar and ended up here. I changed all the paths to variables for program files and programdata (this one saves like 1 character though not as important).
迟到的答案,但我正在寻找类似的东西,最后到了这里。我更改了程序文件和程序数据变量的所有路径(这个保存了 1 个字符,但不那么重要)。
For something like nodejs, i changed the normal path of
对于像nodejs这样的东西,我改变了正常路径
C:\Program Files\nodejs\
C:\Program Files\nodejs\
to
到
%ProgramFiles%\nodejs\
%ProgramFiles%\nodejs\
This can be done with "C:\Program Files (x86)\" as well using "%ProgramFiles(x86)%\"
这可以通过 "C:\Program Files (x86)\" 完成,也可以使用 "%ProgramFiles(x86)%\"
It saved me a few characters but enough that it stopped complaining I feel.
它为我节省了几个字符,但足以让我不再抱怨。
回答by B E
I found you can do via PowerShell.
我发现您可以通过 PowerShell 进行操作。
[System.Environment]::SetEnvironmentVariable("PATH", "C:\Program Files (x86......etc.....", "Machine")
So I grabbed existing system PATH, pasted into notepad, added my new thing, then pasted into the "C:\Program Files" bit of the above. Path updated. Done.
所以我抓住现有的系统路径,粘贴到记事本中,添加我的新东西,然后粘贴到上面的“C:\Program Files”位。路径已更新。完毕。
回答by Amir
In addition to other methods (e.g. Powershell), I found a nice GUI, "Rapid Environment Editor" that can handle larger text values.
除了其他方法(例如 Powershell),我发现了一个不错的 GUI,“快速环境编辑器”,可以处理较大的文本值。
回答by yu yang Jian
Try modify by regedit
, in my case it works when length more than 3000.
尝试 modify by regedit
,在我的情况下,它在长度超过 3000 时有效。
Press Win + R
and enter regedit
to open regedit. Go to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
, and modify value of Path
to your path. And restart computer, it should works.
按Win + R
回车regedit
键打开 regedit。转到Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
,并将 的值修改Path
为您的路径。并重新启动计算机,它应该可以工作。
回答by LeoZ
Workaround:
解决方法:
Please restart the system. After restarting the system, PATH is no longer empty, but may get truncated to 2047 (4095) characters If the system restart does not help please:
请重新启动系统。重新启动系统后,PATH 不再为空,但可能会被截断为 2047 (4095) 个字符如果系统重新启动没有帮助,请:
Launch c:\windows\system32\regedit.exe Go to the registry hive "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Clean up unnecessary directories from the “Path” key Restart the system
启动 c:\windows\system32\regedit.exe 进入注册表配置单元“HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” 清除“Path”键不需要的目录 重启系统
Note: In some exceptional cases if the system is not able to start please:
注意:在某些特殊情况下,如果系统无法启动,请:
Login in the safe mode Open the command prompt shell and type: reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d ^%SystemRoot^%\system32;^%SystemRoot^% /f
以安全模式登录打开命令提示符shell并输入:reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d ^%SystemRoot^%\system32;^%SystemRoot^% /F
For more details: https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable
更多详情:https: //software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable
回答by Christoph Adamakis
Workarround. Use Edit Text and edit your PATH in a text Editor
解决方法。使用编辑文本并在文本编辑器中编辑您的 PATH