抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

0. 安装前准备

打开 控制面板> 程序>启用或关闭Windows功能,开启其中的Virtual Machine Platform(虚拟机平台)和适用于Linux的Windows子系统

1. 安装

1
wsl --install ubuntu

2. 换源

以阿里云为例,可依据下载速度自行替换

1
2
3
sudo sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list
sudo sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list
sudo apt update && sudo apt upgrade -y

3. 配置代理[1] (可选)

将下面函数加入到~/.profile中,记得编辑端口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*') #获得网关地址
export proxyPort=1080 #端口
alias proxy='
export https_proxy="http://${hostip}:${proxyPort}";
export http_proxy="http://${hostip}:${proxyPort}";
export all_proxy="http://${hostip}:${proxyPort}";
echo -e "Acquire::http::Proxy \"http://${hostip}:${proxyPort}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null; echo -e "Acquire::https::Proxy \"http://${hostip}:${proxyPort}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
alias unproxy='
unset https_proxy;
unset http_proxy;
unset all_proxy;
sudo sed -i -e "/Acquire::http::Proxy/d" /etc/apt/apt.conf.d/proxy.conf;
sudo sed -i -e "/Acquire::https::Proxy/d" /etc/apt/apt.conf.d/proxy.conf;
'

更新配置并测试可用性:

1
2
3
4
source ~/.profile #加载环境
proxy #开启代理
curl https://www.google.com #请求Google网址
unproxy #关闭代理

4. 配置中文环境(可选)

1
2
3
4
5
6
sudo apt install language-pack-zh-hans
sudo dpkg-reconfigure locales
#语言选择en_US.UTF-8、zh_CN.UTF-8,默认语言选择zh_CN.UTF-8
sudo apt install fontconfig
sudo apt install --reinstall ttf-mscorefonts-installer
sudo apt install ttf-wqy-zenhei

wsl --shutdown退出重进。

安装中文输入法,ibus、fcitx二者选其一:

1
2
3
4
5
6
#ibus:
sudo apt install ibus ibus-pinyin
ibus-setup #启动输入法服务并配置输入法
#fcitx:
sudo apt install fcitx fcitx-frontend-gtk2 fcitx-frontend-gtk3 fcitx-libpinyin
fcitx-configtool #配置输入法

5. 配置OhMyZsh及PowerLevel10k主题(可选)

安装zsh及OhMyZsh

1
2
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装PowerLevel10k主题

1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

~/.zshrc中设置ZSH_THEME="powerlevel10k/powerlevel10k"保存,exit重启zsh开始设置PowerLevel10k

安装命令补全及代码高亮插件

1
2
3
cd $ZSH_CUSTOM/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions.git
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

打开.zshrc,引入插件:

1
2
3
4
5
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)

更新配置:

1
source ~/.zshrc

6. 安装Docker

方式一 安装Docker Desktop(推荐)

下载地址:Docker Desktop - Docker

配置好WSL2的情况下,Docker Desktop安装时会默认勾选Use WsL 2 instead of Hyper-V (recommended),直接安装即可。

方式二 Linux方式

判断是否已启用Systemd:

1
ps --no-headers -o comm 1

若返回结果为init,需要启用Systemd才可以安装Docker

启用Systemd:

1
sudo echo -e "[boot]\nsystemd=true" | sudo tee -a /etc/wsl.conf

安装Docker:

1
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

安装最新版本 Docker-compose(目前为 2.13.0):

1
curl -L "https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-composechmod +x /usr/local/bin/docker-composeln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

评论