一、启用WSL功能
搜索框输入“启用或关闭Windows功能”
勾选 适用于Linux的Windows子系统,系统会自动配置,然后重启即可。
二、安装linux分发版
直接在微软应用商店搜索,比如安装Ubuntu。安装之后即可启动,设置用户名密码,速度很快。
设置要由 WSL 2 支持的发行版:
可以看到当前系统的Linux 分发版列表:
若要将分发版设置为受某一 WSL 版本支持,请运行:
wsl --set-version <distribution name> <versionNumber>
// 比如
wsl --set-version ubuntu 2
此外,如果要使 WSL 2 成为你的默认体系结构,可以通过此命令执行该操作,这会将安装的任何新分发版的版本设置为 WSL 2:
wsl --set-default-version 2
三、其他一些可选操作
1. 更新软件源并更新
首先备份一下默认的源:
cp /etc/apt/sources.list /etc/apt/sourses.list.bak
sudo tee /etc/apt/sources.list << EOF
deb http://mirrors.163.com/ubuntu/ $(lsb_release -cs) main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ $(lsb_release -cs)-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ $(lsb_release -cs)-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ $(lsb_release -cs)-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ $(lsb_release -cs)-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ $(lsb_release -cs) main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ $(lsb_release -cs)-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ $(lsb_release -cs)-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed $(lsb_release -cs) restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports $(lsb_release -cs) restricted universe multiverse
EOF
sudo apt-get update
sudo apt-get upgrade -y
2. 安装并配置 Docker 环境
sudo apt-get install -y apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
如果提示:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
可以手动启动docker服务
service docker start