admin管理员组

文章数量:1530844

在 Windows 10 中安装 WSL (适用于 Linux 的 Windows 子系统)

信息:

  1. 本文图片中的 Windows 10 是英文版。
  2. 本文以安装 Ubuntu 18.04 LTS 为例。
  3. 本文只安装了CUI。
  4. 不提供担保。

文章目录

  • 在 Windows 10 中安装 WSL (适用于 Linux 的 Windows 子系统)
    • 官方文档
    • 安装步骤
      • 1. 启用 Windows 功能
      • 2. 在应用商店中下载并安装 WSL
    • 3. 设置用户
    • 4. 后续工作
      • 4.1 首次使用 apt 获取软件包前,您应该先更新源
      • 4.2 您可以在 Windows Terminal 中使用WSL
      • 4.3 您可以运行 ``wsl`` 启动 WSL
      • 4.4 用文件资源管理器访问 WSL 中的文件
    • Enjoy it!

官方文档

Microsoft Docs: 适用于 Linux 的 Windows 子系统文档 (https://docs.microsoft/zh-cn/windows/wsl/)

安装步骤

1. 启用 Windows 功能

搜索并打开“启用或关闭 Windows 功能”,然后选择“适用于Linux的Windows子系统”复选框。

信息: 点击确定后,您可能会被要求重启电脑。

2. 在应用商店中下载并安装 WSL

搜索并打开 Microsoft Store, 然后搜索 “Ubuntu”,并选择一个版本下载。

提示: 您也可以搜索 “WSL” 或其他 Linux 发行版,如 Debian 等。

下载可能需要一些时间。

3. 设置用户

当您首次打开 WSL 后,会提示您输入新用户名和密码。

Enter new UNIX username:
Enter new UNIX password:
Retype new UNIX password:

提示: 输入密码时,密码不会被显示。

当出现 Installation successful! 提示则表明配置完成。

提示: 要以 root 权限运行命令,您应该 sudo <command>

4. 后续工作

4.1 首次使用 apt 获取软件包前,您应该先更新源

如果你使用 apt 命令,您应该先将源改为国内的镜像(以阿里云为例)。

  1. 备份 sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  1. 编辑 sources.list
sudo vi /etc/apt/sources.list

在 Vim 编辑器中,删除所有内容,并粘贴如下内容

deb http://mirrors.aliyun/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun/ubuntu/ bionic-backports main restricted universe multiverse

注意: 您应该输入和您的 WSL 版本匹配的镜像地址。

  1. Update 和 upgrade
sudo apt update
sudo apt upgrade

4.2 您可以在 Windows Terminal 中使用WSL

在应用商店中安装 Windows Terminal,然后即可看到 WSL。

4.3 您可以运行 wsl 启动 WSL

在命令提示符中,输入 wsl ,即可打开WSL。

4.4 用文件资源管理器访问 WSL 中的文件

在地址栏中输入网络位置 \\wsl$ ,即可访问 WSL 的文件。

Enjoy it!

至此,WSL 安装完成。

本文标签: 适用于子系统WindowsLinuxWSL