2026年6月5日

技术教程 解决wsl –update和wsl –install时出现E_ACCESSDENIED错误的问题

作者 TheWhiteDog9487

问题表现

PowerShell 7.6.2
Loading personal and system profiles took 560ms.
PS C:\Users\TheWhiteDog9487> ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
False
PS C:\Users\TheWhiteDog9487> sudo pwsh
PowerShell 7.6.2
Loading personal and system profiles took 568ms.
PS C:\Users\TheWhiteDog9487> ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
True
PS C:\Users\TheWhiteDog9487> wsl --update
正在检查更新。
正在更新适用于 Linux 的 Windows 子系统: 2.7.3。
拒绝访问。
错误代码: Wsl/UpdatePackage/E_ACCESSDENIED
PS C:\Users\TheWhiteDog9487> wsl --install archlinux
正在下载: Arch Linux
拒绝访问。
错误代码: Wsl/InstallDistro/E_ACCESSDENIED
PS C:\Users\TheWhiteDog9487> wsl --install archlinux --web-download
正在下载: Arch Linux
拒绝访问。
错误代码: Wsl/InstallDistro/E_ACCESSDENIED
PS C:\Users\TheWhiteDog9487>

临时解决方案

# 1. Create a temp folder where you have access to. For example, D:\temp
mkdir D:\temp
# 2. Point the envs to this folder
$env:TEMP = 'D:\temp'
$env:TMP = 'D:\temp'

使用PowerShell在当前Shell会话内重定向TEMP和TMP这两个控制临时文件夹的环境变量,然后正常运行命令。

或者,你也可以直接移除临时文件夹的隐藏属性

attrib "$env:TEMP"
attrib "$env:TMP"
# If there is a H in the output. That means the folder is set to hidden.
# The following command will remove that label if that's the case.
attrib -H "$env:TEMP"
attrib -H "$env:TMP"

这个方案相比上面那个,最大的好处是可以彻底解决问题,不需要每次执行命令之前都要重定向。
但是由于修改了系统文件夹的默认设置,有一定可能导致其他问题出现,所以不太建议使用。

彻底解决方案

这是WSL自身实现的Bug,在调查出原因之后已经存在修复PR,预计不久之后这个问题会被彻底解决。
因此建议静待更新。
详见:
cannot use `wsl –update` to update WSL, nor use `wsl –install` to install a Linux distribution · Issue #40662 · microsoft/WSL
Fix E_ACCESSDENIED during download if temp is hidden by chemwolf6922 · Pull Request #40708 · microsoft/WSL