How to Resolve Environment Variable Is Too Large On Windows Platform

You may stumble upon a situation like you need to add specific directory into your system path Environment Variable. But somehow, you’re not able to do so, as you got error “Environment variable is too large”. In this article, I will show you how to resolve Environment Variable Is Too Large.


Environment Variable Is Too Large

How to Resolve Environment Variable Is Too Large

There are five(5) solutions:

A.Create new system variable

Create a new system variable. For example %PATH2%.

Assign the path directory location directly to %PATH2%.

Environment Variable Is Too Large
Environment Variable Is Too Large

Then, append the new system variable or “;%PATH2%


Environment Variable Is Too Large

B. Group the value of the path

Verify if you can shorten or group the path. Example, “C:\Program Files\GeekZag\Application\v2020” and “C:\Program Files\GeekZag\Temp\Variable“.

Environment Variable Is Too Large

You can shorten or group it as “C:\Program Files\GeekZag“.

Environment Variable Is Too Large

C. Use too Rapid Environment Variable

This utility is free and you can download it from here. You may use this tool to:

i. Cleanup Paths by removing duplicate paths. This can be done by right click on “Path”, then choose “Cleanup paths”.

Environment Variable Is Too Large

ii. Delete non-exists folders. The non-exists folder will be show in red. You may need to delete it manually.


iii. Replace long path to short path. This can be done by right click at the “Path”, then choose “Convert long path to short”

Environment Variable Is Too Large

D. Bypass variable length limit using Powershell

Before you proceed, it is recommend to backup your current Environment Variable PATH. Copy current PATH, paste and save somewhere else in text file. In case, something went wrong, you can recover the orginal PATH (before changes).

Once you backed up the PATH, run Powershell ISE as administrator

add below command into .ps1 file(“FirstFolderToAddToPath” and “SecondFolderToAddToPath”, indicate the folder location you want to add).

$newPath = $env:Path + ‘; C:\FirstFolderToAddToPath; C:\SecondFolderToAddToPath;’


[Environment]::SetEnvironmentVariable(“Path”, $newPath, “Machine”)

$env:Path = $newPath

Then run the command.

E. Modify using Regedit

Run “Regedit” as administrator.

Then navigate to “Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment“.


Environment Variable Is Too Large

Right click on “Path” and choose “Modify”.

Add the path with semicolon, like “C:\GeekZag;“. Semicolon indicate end of entry.

Click “OK”. Close “Regedit” and reboot your machine.

Conclusion

There are multiple ways that you can do to resolve this issue.

Thanks for reading this article. I hope you find it helpful. You may want to visit Powershell section and discover more information.


Leave a Comment