Windows Server 安装指南Windows Server Installation Guide

适用于 Linux 的 Windows 子系统可供在 Windows Server 2019(版本 1709)和更高版本上安装。The Windows Subsystem for Linux is available for installation on Windows Server 2019 (version 1709) and later. 本指南将指导你完成在计算机上启用 WSL 的步骤。This guide will walk through the steps of enabling WSL on your machine.

启用适用于 Linux 的 Windows 子系统Enable the Windows Subsystem for Linux

必须启用“适用于 Linux 的 Windows 子系统”可选功能并重启,然后才能在 Windows 上运行 Linux 发行版。Before you can run Linux distros on Windows, you must enable the "Windows Subsystem for Linux" optional feature and reboot.

以管理员身份打开 PowerShell 并运行:Open PowerShell as Administrator and run:

    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

下载 Linux 分发版Download a Linux distribution

按照这些说明下载你最喜爱的 Linux 发行版。Follow these instructions to download your favorite Linux distribution.

提取并安装 Linux 分发版Extract and install a Linux distribution

下载 Linux 分发版后,若要提取其内容并进行手动安装,请执行以下步骤:Now that you've downloaded a Linux distribution, in order to extract its contents and manually install, follow these steps:

  1. 使用 PowerShell 提取 <distro>.appx 包的内容:Extract the <distro>.appx package's contents, using PowerShell:

    Rename-Item .\Ubuntu.appx .\Ubuntu.zip
    Expand-Archive .\Ubuntu.zip .\Ubuntu
    
  2. 在目标文件夹中运行分发版启动器应用程序。Run the distribution launcher application in the target folder. 启动器通常命名为 <distro>.exe(例如,ubuntu.exe)。The launcher is typically named <distro>.exe (for example, ubuntu.exe).

    Windows Server 上展开的 Ubuntu 发行版

注意

安装失败并出现错误 0x8007007e:如果收到此错误,则表明系统不支持 WSL。Installation failed with error 0x8007007e: If you receive this error, then your system doesn't support WSL. 请确保运行的是 Windows 版本 16215 或更高版本。Ensure that you're running Windows build 16215 or later. 检查内部版本Check your build. 另外,请进行检查以确认 WSL 已启用,并且在启用此功能后重新启动了计算机。Also check to confirm that WSL is enabled and your computer was restarted after the feature was enabled.

3. 使用 PowerShell 将你的分发版路径添加到 Windows 环境路径(在本例中为 C:\Users\Administrator\Ubuntu):3.Add your distro path to the Windows environment PATH (C:\Users\Administrator\Ubuntu in this example), using PowerShell:

$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Administrator\Ubuntu", "User")

现在,可以通过键入 <distro>.exe 从任何路径启动你的分发版。You can now launch your distribution from any path by typing <distro>.exe. 例如: ubuntu.exeFor example: ubuntu.exe.

安装了分发版后,必须先初始化新的分发版实例,然后才能使用它。Now that it is installed, you must initialize your new distribution instance before using it.