Windows 10(WSL) 安装Linux发行版Ubuntu18.04

Windows 10(WSL) 安装Linux发行版Ubuntu系统

启用适用于Linux的Windows子系统

要使用WSL需要先启用“适用于Linux的Windows子系统”可选功能,然后才能在Windows上安装Linux

以管理员身份打开PowellShell并运行:

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

若不需要安装WSL2则可以重启计算机后开始安装Linux

安装WSL2

WSL 1与WSL 2

功能WSL 1WSL 2
Windows 和 Linux 之间的集成
启动时间短
与传统虚拟机相比,占用的资源量少
可以与当前版本的 VMware 和 VirtualBox 一起运行
托管 VM
完整的 Linux 内核
完全的系统调用兼容性
跨 OS 文件系统的性能

WSL 2安装要求(windows 10)

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

启用虚拟机

安装WSL 2之前,必须启用“虚拟机平台”

  • 以管理员身份运行PowerShell

    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  • 重启计算机

安装Linux内核更新包

将WSL2 设为默认版本

以管理员身份运行PowerShell

wsl --set-default-version 2

安装Linux

  • 在windows应用商店(Microsoft Store)中搜索Linux并安装你需要的版本

    在这里插入图片描述

  • 为你的Linux子系统创建用户账户和密码

    在这里插入图片描述

将Linux子系统移动到非C盘

  1. 查看已安装Linux子系统

    在这里插入图片描述

  2. 导出子系统到E盘

    wsl --export Ubuntu-18.04 e:\wsl-ubuntu18.04.tar
    
  3. 注销当前子系统

    wsl --unregister Ubuntu-18.04
    
  4. 重新导入WSL并安装在E盘

    wsl --import Ubuntu-18.04 e:\wsl-ubuntu18.04 e:\wsl-ubuntu18.04.tar
    
  5. 设置默认登录用户为安装时的用户名

    ubuntu18.04 config --default-user USERNAME
    
  6. 删除wsl-ubuntu18.04.tar

    del e:\wsl-ubuntu18.04.tar
    

更换源

  1. 备份apt源列表文件

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 编辑源列表文件

    sudo vim /etc/apt/sources.list
    
  3. 删除或注释原列表内容,并添加一下内容

    • Ubuntu

      ## 18.04LTS
      # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
      # 预发布软件源,不建议启用
      # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
      
      =============================================================================================
      
      ## 20.04LTS
      # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
      deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
      # 预发布软件源,不建议启用
      # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
      
  4. 更新源

    sudo apt-get update
    sudo apt-get upgrade
    

版权声明:本文为qq_38162575原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。