WSL-Debian GNU/Linux安装

1,272 阅读2分钟

启用适用于 Linux 的 Windows 子系统

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

检查运行 WSL 2 的要求

Windows 徽标键 + R,然后键入“winver”,检查windows10版本号

  1. 对于 x64 系统:版本 1903 或更高版本,采用 内部版本 18362 或更高版本。
  2. 对于 ARM64 系统:版本 2004 或更高版本,采用 内部版本 19041 或更高版本。
  3. 低于 18362 的版本不支持 WSL 2。 使用 Windows Update 助手更新 Windows 版本

启用虚拟机功能

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

下载 Linux 内核更新包

适用于 x64 计算机的 WSL2 Linux 内核更新包

将 WSL 2 设置为默认版本

wsl --set-default-version 2

安装所选的 Linux 分发

  1. 打开 Microsoft Store,并选择你偏好的 Linux 分发版并安装,建议选择Debian
  2. 为linux创建用户名和密码

设置WSL版本

通过执行以下的Powershell命令可以将Debian设为受WSL2支持

wsl --set-version Debian 2

如果提示

WSL 2 requires an update to its kernel component. For information please visit aka.ms/wsl2kernel。

则需要安装 MSI Linux 内核更新包

更换清华大学源

  1. 先进行apt更新

    sudo apt-get update
    
  2. 替换为清华大学源

    Debian 的软件源配置文件是 /etc/apt/sources.list,建议先进行备份。

    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
    

    执行更新命令

    sudo apt-get update