WSL 2 的安装说明Installation Instructions for WSL 2

若要安装并开始使用 WSL 2,请完成以下步骤:To install and start using WSL 2 complete the following steps:

WSL 2 仅适用于 Windows 10 版本18917或更高版本WSL 2 is only available in Windows 10 builds 18917 or higher

  • 确保已安装 WSL (可以在此处找到相关说明),并且运行的是 Windows 10内部版本 18917或更高版本Ensure that you have WSL installed (you can find instructions to do so here) and that you are running Windows 10 build 18917 or higher
    • 若要确保使用的是版本18917或更高版本,请加入Windows 预览体验计划,并选择 "快速" 环或 "慢速" 环。To make sure you are using build 18917 or higher please join the Windows Insider Program and select the 'Fast' ring or the 'Slow' ring.
    • 可以通过打开命令提示符并运行 ver 命令来检查 Windows 版本。You can check your Windows version by opening Command Prompt and running the ver command.
  • 启用“虚拟机平台”可选组件Enable the 'Virtual Machine Platform' optional component
  • 使用命令行设置要由 WSL 2 支持的发行版Set a distro to be backed by WSL 2 using the command line
  • 验证发行版使用的 WSL 版本Verify what versions of WSL your distros are using

启用 "虚拟机平台" 可选组件,并确保已启用 WSLEnable the 'Virtual Machine Platform' optional component and make sure WSL is enabled

你将需要确保你已安装适用于 Linux 的 Windows 子系统和已安装的虚拟机平台可选组件。You will need to make sure that you have both the Windows Subsystem for Linux and the Virtual Machine Platform optional components installed. 可以通过在 PowerShell 中运行以下命令来执行此操作:You can do that by running the following command in PowerShell:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

请重新启动计算机以完成两个组件的安装。Please restart your machine to finish installing both components.

使用命令行设置要由 WSL 2 支持的发行版Set a distro to be backed by WSL 2 using the command line

如果尚未安装 Linux 发行版,请参阅在Windows 10 文档上安装页,获取有关安装一个的说明。If you do not have a Linux distro installed, please refer to the Install on Windows 10 docs page for instructions on installing one.

若要设置发行版,请运行:To set a distro please run:

wsl --set-version <Distro> 2

并且确保将 <Distro> 替换为你的发行版的实际名称。and make sure to replace <Distro> with the actual name of your distro. (可使用以下命令找到这些内容:wsl -l)。(You can find these with the command: wsl -l). 可以随时更改回 WSL 1,方法是运行与上面相同的命令,但将“2”替换为“1”。You can change back to WSL 1 at anytime by running the same command as above but replacing the '2' with a '1'.

此外,如果要使 WSL 2 成为你的默认体系结构,可以通过此命令执行该操作:Additionally, if you want to make WSL 2 your default architecture you can do so with this command:

wsl --set-default-version 2

这会使你安装的任何新发行版均初始化为 WSL 2 发行版。This will make any new distro that you install be initialized as a WSL 2 distro.

完成验证发行版使用的 WSL 版本Finish with verifying what versions of WSL your distro are using

若要验证每个发行版使用的 WSL 版本,请使用以下命令(仅适用于 Windows 版本18917或更高版本):To verify what versions of WSL each distro is using use the following command (only available in Windows Build 18917 or higher):

wsl --list --verbosewsl -l -vwsl --list --verbose or wsl -l -v

上面选择的发行版现在应在“version”列下显示“2”。The distro that you've chosen above should now display a '2' under the 'version' column. 既然已经完成,便可以随时开始使用 WSL 2 发行版了!Now that you're finished feel free to start using your WSL 2 distro!

疑难解答:Troubleshooting:

下面是安装 WSL 2 时的相关错误和建议的修补程序。Below are related errors and suggested fixes when installing WSL 2. 请参阅 WSL 故障排除页以了解其他常见的 WSL 错误及其解决方案。Please refer to the WSL troubleshooting page for other general WSL errors and their solutions.

  • 安装失败,出现错误 0x80070003 或错误 0x80370102Installation failed with error 0x80070003 or error 0x80370102

    • 请确保在计算机的 BIOS 内已启用虚拟化。Please make sure that virtualization is enabled inside of your computer's BIOS. 有关如何执行此操作的说明因计算机而异,并且很可能在 CPU 相关选项下。The instructions on how to do this will vary from computer to computer, and will most likely be under CPU related options.
  • 尝试升级时出错:Invalid command line option: wsl --set-version Ubuntu 2Error when trying to upgrade: Invalid command line option: wsl --set-version Ubuntu 2

    • 请确保已启用适用于 Linux 的 Windows 子系统,并且你使用的是 Windows 内部版本 18917 或更高版本。Please make sure that you have the Windows Subsystem for Linux enabled, and that you're using Windows Build version 18917 or higher. 若要启用 WSL,请在 Powershell 提示符下以具有管理员权限的身份运行此命令:Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-LinuxTo enable WSL run this command in a Powershell prompt with admin privileges: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux. 可在此处找到完整的 WSL 安装说明。You can find the full WSL install instructions here.
  • 由于虚拟磁盘系统限制,无法完成请求的操作。虚拟硬盘文件必须是解压缩和未加密的,并且不能是稀疏的。The requested operation could not be completed due to a virtual disk system limitation. Virtual hard disk files must be uncompressed and unencrypted and must not be sparse.

  • 术语 "wsl" 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program.