1. wsl-安装适用于 Linux 的 Windows 子系统:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
2. 启用“虚拟机平台”可选组件
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
3. 重启后安装linux内核
# 下载地址:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi wsl --set-default-version 2 # wsl -l -v # 查看目前WSL版本
4. 在 PowerShell 中,将 WSL 默认版本设置为2,这样之后安装的 Linux 发行版才会都安装在 WSL2 中。
wsl --set-default-version 2
5. Microsoft Store 中搜索下载安装 Linux 发行版, 比如 Ubuntu 18.04。
输入账户不要大写开头,输入密码时不要用中文输入法
Enter new UNIX username: grant_linux Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Installation successful! To run a command as administrator (user "root"), use "sudo". See "man sudo_root" for details.
6. 在 PowerShell 中使用如下命令可以检查是否安装成功:
wsl --list --verbose
7 ubuntu配置使用
换源:
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list # 编辑更换为清华源: https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/ sudo vi /etc/apt/sources.list
清华源
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
更新源
# 更新源 sudo apt-get update # 更新软件 sudo apt-get upgrade
8. 安装python3.7
# 阿里云源有坑,有依赖安装不上。
sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python3.7 sudo wget https://bootstrap.pypa.io/get-pip.py sudo python3.7 get-pip.py #安装python3.7-develop 包 sudo apt install python3.7-dev python3 --version pip3 --version
来个示例图: