Frequently Asked Questions about Windows 子系统适用于 LinuxFrequently Asked Questions about Windows Subsystem for Linux

什么是 Windows 子系统用于 Linux (WSL)?What is Windows Subsystem for Linux (WSL)?

Windows 子系统用于 Linux (WSL) 是一个新的 Windows 10 功能,使您能够直接在 Windows 上运行本机 Linux 命令行工具,以及传统 Windows 桌面和新式应用商店应用。The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that enables you to run native Linux command-line tools directly on Windows, alongside your traditional Windows desktop and modern store apps.

请参阅有关页面的更多详细信息。See the about page for more details.

有关 WSL 是谁?Who is WSL for?

这是开发人员-尤其是 web 开发人员和工作或使用开放源代码项目的员工的主要工具。This is primarily a tool for developers -- especially web developers and those who work on or with open source projects. 这允许那些希望/需要使用 Bash,常见的 Linux 工具 (sedawk等) 和许多 Linux 第一个工具 (Ruby、 Python 等) 在 Windows 上使用其工具链。This allows those who want/need to use Bash, common Linux tools (sed, awk, etc.) and many Linux-first tools (Ruby, Python, etc.) to use their toolchain on Windows.

使用 WSL 可以做什么?What can I do with WSL?

WSL 提供应用程序 Bash.exe,启动时调用,此时会打开一个 Windows 控制台运行的 Bash shell。WSL provides an application called Bash.exe that, when started, opens a Windows console running the Bash shell. 使用 Bash,可以运行 Linux 的命令行工具和应用程序。Using Bash, you can run command-line Linux tools and apps. 例如,键入lsb_release -a并按 enter,可以看到当前正在运行的 Linux 发行版的详细信息:For example, type lsb_release -a and hit enter; you’ll see details of the Linux distro currently running:

发行版的详细信息的屏幕截图

您还可以访问从 Linux Bash shell 中的本地计算机的文件系统-您会发现您的本地驱动器装载在/mnt文件夹。You can also access your local machine’s filesystem from within the Linux Bash shell – you’ll find your local drives mounted under the /mnt folder. 例如,你C:驱动器装载在/mnt/c:For example, your C: drive is mounted under /mnt/c:

加载的 C 驱动器的屏幕截图

什么是 Bash?What is Bash?

Bash是一种流行的基于文本的外壳和命令语言。Bash is a popular text-based shell and command-language. 它是包含在 Ubuntu 和其他 Linux 发行版中,并在 macOS 中的默认外壳。It is the default shell included within Ubuntu and other Linux distros, and in macOS. 用户键入到 shell 中执行脚本和/或运行命令和工具来完成许多任务的命令。Users type commands into a shell to execute scripts and/or run commands and tools to accomplish many tasks.

这是如何实现的?How does this work?

请查看我们博客我们进入有关基础技术的详细信息。Check out our blog where we go into detail about the underlying technology.

为什么要使用 WSL 而不是 Linux VM 中?Why would I use WSL rather than Linux in a VM?

WSL 需要较少的资源 (CPU、 内存和存储) 比完整的虚拟机。WSL requires fewer resources (CPU, memory, and storage) than a full virtual machine. WSL 还允许您运行 Linux 命令行工具和应用程序和 Windows 命令行中,桌面和应用商店应用,以及访问 Windows 文件从 Linux 中。WSL also allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux. 这样,如果你想在同一组文件上使用 Windows 应用和 Linux 命令行工具。This enables you to use Windows apps and Linux command-line tools on the same set of files if you wish.

为什么要使用,例如,而不是在 Windows 上的 Linux 上的 Ruby?Why would I use, for example, Ruby on Linux instead of on Windows?

假设运行它们的环境的行为类似于 Linux 生成一些跨平台工具。Some cross-platform tools were built assuming that the environment in which they run behaves like Linux. 例如,一些工具假定他们可访问非常长文件路径或特定的文件/文件夹存在。For example, some tools assume that they are able to access very long file paths or that specific files/folders exist. 这通常会造成问题在通常的行为的 Windows 上以不同的方式从 Linux。This often causes problems on Windows which often behaves differently from Linux.

许多语言,如 Ruby 和节点通常是移植到,并在 Windows 上运行很好。Many languages like Ruby and node are often ported to, and run great, on Windows. 但是,并非所有节点/NPM 库所有者的 Ruby Gem 的端口及其库来支持 Windows,并且许多具有特定于 Linux 的依赖项。However, not all of the Ruby Gem or node/NPM library owners port their libraries to support Windows, and many have Linux-specific dependencies. 通常,这可能导致系统使用此类工具和库生成和有时运行时错误或不需要的行为在 Windows 上遇到问题生成。This can often result in systems built using such tools and libraries suffering from build and sometimes runtime errors or unwanted behaviors on Windows.

这些是只是一些导致许多人提出 Microsoft 以提高 Windows 的命令行工具和什么促使我们与 Canonical 启用本机 Bash 和 Linux 命令行工具在 Windows 上运行的问题。These are just some of issues that caused many people to ask Microsoft to improve Windows’ command-line tools and what drove us to partner with Canonical to enable native Bash and Linux command-line tools to run on Windows.

适用于 PowerShell,这意味着什么?What does this mean for PowerShell?

同时使用 OSS 项目时,有许多方案是非常有用,放入 Bash 从 PowerShell 提示。While working with OSS projects, there are numerous scenarios where it’s immensely useful to drop into Bash from a PowerShell prompt. Bash 支持是补充并增强了 Windows,从而允许 PowerShell 和 PowerShell 社区利用其他常用技术上的命令行中的值。Bash support is complementary and strengthens the value of the command-line on Windows, allowing PowerShell and the PowerShell community to leverage other popular technologies.

详细了解的 PowerShell 团队博客- Bash Windows:为什么这真的非常棒和 PowerShell 的含义Read more on the PowerShell team blog -- Bash for Windows: Why it’s awesome and what it means for PowerShell

在 WSL 运行所有 Linux 应用Can I run ALL Linux apps in WSL?

不!No! WSL 是旨在使用户需要使用这些运行 Bash 和 core 在 Windows 上的 Linux 命令行工具的工具。WSL is a tool aimed at enabling users who need them to run Bash and core Linux command-line tools on Windows.

WSL does旨在支持 GUI 桌面或应用程序 (例如 Gnome,KDE,等等。)WSL does not aim to support GUI desktops or applications (e.g. Gnome, KDE, etc.)

此外,即使你将能够运行许多常用的服务器应用程序 (例如 Redis),我们不建议用于托管生产服务 WSL – Microsoft 提供了多种解决方案,用于运行生产 Linux 工作负荷在 Azure 中,HYPER-V 和 Docker。Also, even though you will be able to run many popular server applications (e.g. Redis), we do not recommend WSL for hosting production services – Microsoft offers a variety of solutions for running production Linux workloads in Azure, Hyper-V, and Docker.

WSL 中包括哪些 Windows Sku?What Windows SKUs is WSL included in?

适用于 Linux 的 Windows 子系统是在桌面版本的 Windows 的 Windows 10 周年版及创意者更新或更高版本上可用。Windows Subsystem for Linux is available on the desktop version of Windows for Windows 10 Anniversary and Creators update or later.

从开始 Fall Creators update WSL 将在桌面和服务器 Windows Sku 上可用。Beginning in the Fall Creators update WSL will be available on both the desktop and server SKUs of Windows.

WSL 支持哪些处理器?What processors does WSL support?

WSL 支持 x64 和 ARM Cpu。WSL supports x64 and ARM CPUs.

如何访问我的 c: 驱动器?How do I access my C: drive?

在本地计算机上的硬盘驱动器的装入点自动创建,并可以轻松访问 Windows 文件系统。Mount points for hard drives on the local machine are automatically created and provide easy access to the Windows filesystem.

/mnt/<驱动器号 > //mnt/<drive letter>/

用法示例为cd /mnt/c访问 c:Example usage would be cd /mnt/c to access c:\

如何使用 Linux 应用使用 Windows 文件?How do I use a Windows file with a Linux app?

WSL 的优势之一能够访问你通过 Windows 和 Linux 应用程序或工具的文件。One of the benefits of WSL is being able to access your files via both Windows and Linux apps or tools.

WSL 装载用的计算机的固定的驱动器/mnt/<drive>Linux 发行版中的文件夹。WSL mounts your machine's fixed drives under the /mnt/<drive> folder in your Linux distros. 例如,你C:下装载驱动器 /mnt/c/For example, your C: drive is mounted under /mnt/c/

使用你已装载的驱动器,你可以编辑代码中,例如,C:\dev\myproj\使用Visual Studio / 或VS Code,并生成/测试 Linux 中的代码的访问通过的相同文件/mnt/c/dev/myprojUsing your mounted drives, you can edit code in, for example, C:\dev\myproj\ using Visual Studio / or VS Code, and build/test that code in Linux by accessing the same files via /mnt/c/dev/myproj.

重要说明:使用 WSL 的主要限制之一是,不支持直接访问/更改使用 Windows 应用程序或工具的 Linux 发行版的文件系统中的文件。IMPORTANT NOTE: One of the key limitations of using WSL is that directly accessing/changing files in your Linux distros' filesystem using Windows apps or tools is not supported. 请参阅:不会更改使用 Windows 应用程序和工具的 Linux 文件See: Do not change Linux files using Windows apps and tools

是在 Linux 驱动器中的文件不同于已装载的 Windows 驱动器?Are files in the Linux drive different from the mounted Windows drive?

  1. Linux 根下的文件 (即/) 受 WSL 模拟 Linux 特定行为,包括但不是限于:Files under the Linux root (i.e. /) are controlled by WSL which mimics Linux specific behavior, including but not limited to:

    • 包含无效 Windows 文件名字符的文件Files which contain invalid Windows filename characters
    • 为非管理员用户创建的符号链接Symlinks created for non-admin users
    • 更改通过 chmod 和 chown 文件属性Changing file attributes through chmod and chown
    • 文件/文件夹区分大小写File/folder case sensitivity
  2. 已装载的驱动器中的文件由 Windows 控制,并具有以下行为:Files in mounted drives are controlled by Windows and have the following behaviors:

    • 支持区分大小写Support case sensitivity
    • 所有权限都设置为最能反映 Windows 权限All permissions are set to best reflect the Windows permissions

为什么有这么多的错误时运行的 apt-get 升级?Why are there so many errors when I run apt-get upgrade?

某些包使用我们尚未实现的功能。Some packages use features that we haven't implemented yet. udev例如,尚不支持并导致多apt-get upgrade错误。udev, for example, isn't supported yet and causes several apt-get upgrade errors.

若要修复与相关的问题udev,请执行以下步骤:To fix issues related to udev, follow the following steps:

  1. 写入到以下/usr/sbin/policy-rc.d并保存所做的更改。Write the following to /usr/sbin/policy-rc.d and save your changes.

    #!/bin/sh
    exit 101
    
  2. 添加将执行权限 /usr/sbin/policy-rc.dAdd execute permissions to /usr/sbin/policy-rc.d

    chmod +x /usr/sbin/policy-rc.d
    
  3. 运行以下命令Run the following commands

    dpkg-divert --local --rename --add /sbin/initctl
    ln -s /bin/true /sbin/initctl
    

如何卸载 WSL 分发?How do I uninstall a WSL Distribution?

在生成之前 1709 (版本 16299) 打开命令提示符并运行:On builds prior to 1709 (16299) open a command prompt and run:

lxrun /uninstall /full

通过右键单击应用磁贴上,单击卸载,或者通过 PowerShell 使用从应用商店安装 WSL 分发可以卸载其他任何 Windows 应用一样 Remove-AppxPackage cmdletWSL distributions installed from the store can be uninstalled like any other Windows app, by right-clicking on the app tile and clicking Uninstall, or via PowerShell using the Remove-AppxPackage cmdlet.

Ping 为什么生成权限被拒绝错误?Why does ping generate permission denied errors?

在 WSL 中生成 < 14926,ping 所需 WSL 中通过权限提升的控制台运行。In WSL builds < 14926, ping required WSL to run via an elevated Console. 此问题已修复生成 14926 及更高版本。This issue was fixed in Build 14926 and later.

如何运行 OpenSSH 服务器?How do I run an OpenSSH server?

在 Windows 中的管理员权限才可在 WSL 中运行 OpenSSH。Administrator privileges in Windows are required to run OpenSSH in WSL. 若要运行的 OpenSSH 服务器,在作为管理员,Windows 上运行 Ubuntu 上的 Bash 或 CMD/PowerShell 提示符下使用管理员特权运行 bash.exe。To run an OpenSSH server, run Bash on Ubuntu on Windows as an administrator, or run bash.exe from a CMD/PowerShell prompt with administrator privileges.

为何收到"错误:0x80040306"当我尝试安装?Why do I get "Error: 0x80040306" when I try to install?

WSL 不支持旧版控制台中运行。WSL does not support running in a legacy console. 若要关闭旧版控制台:To turn off legacy console:

  1. 打开 WSL、 PowerShell 或 CmdOpen WSL, PowerShell, or Cmd
  2. 右键单击标题栏-> 属性-> 取消选中"使用传统控制台"Right click title bar -> Properties -> Uncheck "Use legacy console"
  3. 单击“确定”Click OK

为何收到"错误:0x80040154"当我运行 bash.exe 升级 Windows 之后?Why do I get "Error: 0x80040154" when I run bash.exe after upgrading Windows?

"Windows 子系统适用于 Linux"功能可能会禁用在 Windows 更新过程。The "Windows Subsystem for Linux" feature may be disabled during a Windows update. 如果发生这种情况必须在重新启用 Windows 功能。If this happens the Windows feature must be re-enabled. 有关启用"Windows 子系统适用于 Linux"功能的说明可在[安装指南](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide#enable-the-windows-subsystem-for-linux-feature-gui https://msdn.microsoft.com/en-us/commandline/wsl/install_guide#enable-the-windows-subsystem-for-linux-feature-gui)。Instructions for enabling the "Windows Subsystem for Linux" feature can be found in the Installation Guide.

如何更改显示语言的 WSL?How do I change the display language of WSL?

WSL 安装将尝试自动更改 Ubuntu 区域设置,以便与 Windows 安装程序的区域设置匹配。WSL install will try to automatically change the Ubuntu locale to match the locale of your Windows install. 如果您不需要此行为可以运行此命令以安装完成后更改 Ubuntu 区域设置。If you do not want this behavior you can run this command to change the Ubuntu locale after install completes. 必须重新启动 bash.exe 此更改才会生效。You will have to relaunch bash.exe for this change to take effect.

下面的示例更改为 EN-US 区域设置:The below example changes to locale to en-US:

sudo update-locale LANG=en_US.UTF8

为什么不具有 internet 访问 WSLWhy do I not have internet access from WSL?

某些用户与特定的防火墙应用程序阻止 internet 访问在 WSL 中的报告的问题。Some users have reported issues with specific firewall applications blocking internet access in WSL. 防火墙报告是:The firewalls reported are:

  1. KasperskyKaspersky
  2. AVGAVG
  3. AvastAvast

在某些情况下关闭防火墙允许访问。In some cases turning off the firewall allows for access. 只需时安装防火墙的某些情况下看起来以阻止访问。In some cases simply having the firewall installed looks to block access.

如何从 Windows 在 WSL 访问端口?How do I access a port from WSL in Windows?

WSL 共享运行在 Windows 上的 Windows,IP 地址。WSL shares the IP address of Windows, as it is running on Windows. 这种情况下可以访问本地主机上的任何端口例如有 web 内容上的端口 1234 可以 https://localhost:1234Windows 浏览器中。As such you can access any ports on localhost e.g. if you had web content on port 1234 you could https://localhost:1234 into your Windows browser.

其中提供反馈?Where can I provide feedback?

可以分享反馈并通过多个通道提问:反馈和问题应定向到:You can share feedback and ask questions through multiple channels: Feedback and questions should be directed to: