一、啓用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