手动下载适用于 Linux 的 Windows 子系统发行版包Manually download Windows Subsystem for Linux distro packages

在多种情况下,你可能无法(或不想)通过 Microsoft Store 安装 WSL Linux 发行版。There are several scenarios in which you may not be able (or want) to, install WSL Linux distros via the Microsoft Store. 具体而言,你可能运行的是不支持 Microsoft Store 或公司网络策略和/或管理员在你的环境中不允许 Microsoft Store 使用的 Windows Server 或长期服务(LTSC)桌面操作系统 SKU。Specifically, you may be running a Windows Server or Long-Term Servicing (LTSC) desktop OS SKU that doesn't support Microsoft Store, or your corporate network policies and/or admins to not permit Microsoft Store usage in your environment.

在这些情况下,虽然 WSL 本身可用,但如果你无法访问应用商店,如何下载并在 WSL 中安装 Linux 发行版?In these cases, while WSL itself is available, how do you download and install Linux distros in WSL if you can't access the store?

注意:不允许在 Windows 10 S 模式上运行命令行 shell 环境,包括 Cmd、PowerShell 和 Linux/WSL 发行版Note: Command-line shell environments including Cmd, PowerShell, and Linux/WSL distros are not permitted to run on Windows 10 S Mode. 存在此限制是为了确保模式提供的完整性和安全性目标:阅读此文章了解详细信息。This restriction exists in order to ensure the integrity and safety goals that S Mode delivers: Read this post for more information.

下载发行版Downloading distros

如果 Microsoft Store 应用不可用,则可以通过单击以下链接下载并手动安装 Linux 发行版:If the Microsoft Store app is not available, you can download and manually install Linux distros by clicking these links:

这将导致 <distro>.appx 包下载到你选择的文件夹。This will cause the <distro>.appx packages to download to a folder of your choosing. 按照安装说明安装下载的发行版。Follow the installation instructions to install your downloaded distro(s).

通过命令行下载发行版Downloading distros via the command line

如果愿意,也可以通过命令行下载首选的发行版:If you prefer, you can also download your preferred distro(s) via the command line:

使用 PowerShell 下载Download using PowerShell

若要使用 PowerShell 下载发行版,请使用WebRequest cmdlet。To download distros using PowerShell, use the Invoke-WebRequest cmdlet. 下面是下载 Ubuntu 16.04 的示例说明。Here's a sample instruction to download Ubuntu 16.04.

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing

提示

如果下载需要很长时间,请通过设置 $ProgressPreference = 'SilentlyContinue' 来关闭进度栏。If the download is taking a long time, turn off the progress bar by setting $ProgressPreference = 'SilentlyContinue'

使用卷下载Download using curl

Windows 10 春季2018更新(或更高版本)包含可从命令行调用 web 请求(例如 HTTP GET、POST、PUT 等命令)的常用卷命令行实用程序Windows 10 Spring 2018 Update (or later) includes the popular curl command-line utility with which you can invoke web requests (i.e. HTTP GET, POST, PUT, etc. commands) from the command line. 您可以使用 curl.exe 下载上述发行版:You can use curl.exe to download the above distros:

curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604

在上面的示例中,将执行 curl.exe (而不只是 curl),以确保在 PowerShell 中调用实卷可执行文件,而不是调用WebRequest的 powershell 卷别名。In the above example, curl.exe is executed (not just curl) to ensure that, in PowerShell, the real curl executable is invoked, not the PowerShell curl alias for Invoke-WebRequest

注意:如果必须使用 Cmd shell 和/或 .bat / .cmd 脚本来调用/编写下载步骤,则使用 curl 可能更可取。Note: Using curl might be preferable if you have to invoke/script download steps using Cmd shell and/or .bat / .cmd scripts.

安装发行版Installing your distro

如果使用的是 Windows 10,则可以使用 PowerShell 安装发行版。If you're using Windows 10 you can install your distro with PowerShell. 只需导航到包含上面下载的发行版的文件夹,并在该目录中运行以下命令,其中 app_name 是发行版文件的名称。Simply navigate to folder containing the distro downloaded from above, and in that directory run the following command where app_name is the name of your distro .appx file.

Add-AppxPackage .\app_name.appx

如果使用的是 Windows server,可以在Windows server文档页上找到安装说明。If you are using Windows server you can find the install instructions on the Windows Server documentation page.

安装发行版后,请参阅初始化步骤页,初始化新的发行版。Once your distro is installed please refer to the Initialization Steps page to initialize your new distro.