在 Windows 10 周年更新和创意者更新上安装或卸载适用于 Linux 的 Windows 子系统的指南Guide to install or uninstall Windows Subsystem for Linux on Windows 10 Anniversary Update and Creators Update

如果运行的是 Windows 10 创意者更新或更高版本,请遵循 windows 10 安装说明If you're running Windows 10 Creators Update or later, please follow the Windows 10 installation instructions.

以下说明适用于运行 Windows 10 周年更新或 Windows 10 创意者更新的用户The following instructions are for users running Windows 10 Anniversary Update or Windows 10 Creators Update

在 Windows 10 秋季创意者更新(版本1709)之前,WSL 已作为 beta 功能发布,并在第一次运行 "在 Windows 上的 Bash on Ubuntu 时安装了一个 Ubuntu 实例"。Prior to Windows 10 Fall Creators Update (version 1709), WSL was released as a beta feature and installed a single Ubuntu instance when "Bash on Ubuntu on Windows" (or Bash.exe) was first run.

尽管可以在早期版本的 Windows 10 版本上使用 WSL,但此 beta "旧发行版" 现在被视为已过时。While you CAN use WSL on earlier Windows 10 releases, this beta "legacy distro" is now considered obsolete. 强烈建议运行最新版本的 Windows 10。We strongly encourage you to run the most recent version of Windows 10 available. 每个新的 Windows 10 版本都单独包括 WSL 中的数百个修补程序和改进功能,使更多的 Linux 工具和应用能够在 WSL 上正常运行。Each new Windows 10 release includes many hundreds of fixes and improvements in WSL alone, allowing ever more Linux tools and apps to run correctly on WSL.

如果无法升级到秋季创意者更新或更高版本,请按照以下步骤启用和使用 WSL:If you cannot upgrade to Fall Creators Update or later, follow the steps below to enable and use WSL:

  1. 开启开发人员模式若要在 Windows 10 周年更新或创意者更新上运行 WSL,必须启用开发人员模式:Turn on Developer Mode To run WSL on Windows 10 Anniversary Update or Creators Update, you must enable Developer Mode:

    为开发人员打开 -> 更新和安全 -> 的设置Open Settings -> Update and Security -> For developers

    选择 "开发人员模式" 单选按钮Select the Developer Mode radio button
    启用开发人员模式

    Windows 10 秋季创意者更新中已删除启用开发人员模式的要求The requirement to enable Developer Mode was removed in Windows 10 Fall Creators Update

  2. 打开命令提示符。Open a command prompt. 键入 bash 并按 enterType bash and hit enter

    首次在 Windows 上的 Ubuntu 上运行 Bash 时,系统将提示你接受规范的许可证。The first time you run Bash on Ubuntu on Windows, you'll be prompted to accept Canonical's license. 接受后,WSL 会将 Ubuntu 实例下载并安装到计算机上,并将在 "开始" 菜单中添加 "Bash on Ubuntu on Windows" 快捷方式。Once accepted, WSL will download and install the Ubuntu instance onto your machine, and a "Bash on Ubuntu on Windows" shortcut will be added to your start menu.

    提示安装 Ubuntu

    首次在 Windows 上的 Ubuntu 上运行 Bash 时,系统将提示你创建 UNIX 用户名和密码。The first time you run Bash on Ubuntu on Windows, you will be prompted to create a UNIX username and password. 按照新的发行版实例说明完成安装Follow the new distro instance instructions to complete your installation

  3. 通过以下方法之一启动新的 Ubuntu shell:Launch a new Ubuntu shell by either:

    • 从命令提示符运行 bashRunning bash from a command-prompt
    • 单击 "开始" 菜单 "在 Windows 上打开 Ubuntu on Ubuntu" 快捷方式Clicking the start menu "Bash on Ubuntu on Windows" shortcut

卸载/删除旧发行版Uninstalling/Removing the legacy distro

如果从安装了 WSL 的早期 Windows 10 版本升级到 Windows 10 秋季创意者更新,则现有发行版将保持不变。If you upgrade to Windows 10 Fall Creators Update from an earlier Windows 10 release upon which you installed WSL, your existing distro will remain intact. 但是,我们强烈建议你尽快安装新的存储提供的发行版,并将所有必要的文件、数据等从旧发行版迁移到新的发行版。However, we STRONGLY encourage you to install a new Store-delivered distro ASAP, and migrate any necessary files, data, etc. from your legacy distro to your new distro.

若要从计算机中删除旧的发行版,请从命令行或 PowerShell 实例运行以下命令:To remove the legacy distro from your machine, run the following from a Command Line or PowerShell instance:

wsl --unregister Legacy

如果未使用 Windows 版本1903或更高版本,则可能需要改为运行 wslconfig /u Legacylxrun /uninstall /fullIf you are not using Windows Version 1903 or higher, you may need to run wslconfig /u Legacy or lxrun /uninstall /full instead.

手动删除旧发行版Manually deleting the legacy distro

如果需要,可以手动删除旧实例。If you wish, you can manually delete your legacy instance. 如果使用 lxrun.exe卸载旧的发行版或运行 Windows 10 春季2018更新(或更高版本),但未附带 lxrun.exe,则可能需要执行此操作。This may be required if you encounter issues uninstalling the legacy distro using lxrun.exe, or are running Windows 10 Spring 2018 Update (or later) which do not ship with lxrun.exe.

若要强制删除旧的 WSL 发行版,请使用 Windows 文件资源管理器或命令行删除 %localappdata%\lxss\ 文件夹(及其所有子内容):To forcefully delete your legacy WSL distro, delete the %localappdata%\lxss\ folder (and all it's sub-contents) using Windows' File Explorer, or the command-line:

使用 PowerShellUsing PowerShell

rm -Recurse $env:localappdata/lxss/

使用 Cmd:Using Cmd:

DEL /S %localappdata%\lxss\