本文最后更新于 776 天前,其中的信息可能已经有所发展或是发生改变。
1. 安装
wsl --install ubuntu
2. 换源
以阿里云为例,可依据下载速度自行替换
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
中,记得编辑端口:
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;
'
更新配置并测试可用性:
source ~/.profile #加载环境
proxy #开启代理
curl https://www.google.com #请求Google网址
unproxy #关闭代理
4. 配置中文环境(可选)
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二者选其一:
#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
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安装PowerLevel10k主题
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
安装命令补全及代码高亮插件
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
,引入插件:
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
更新配置:
source ~/.zshrc
6. 安装Docker Desktop
方式一 安装Docker Desktop
配置好WSL2的情况下,Docker Desktop安装时会默认勾选“Use WsL 2 instead of Hyper-V (recommended)”,直接安装即可。
方式二 Linux推荐方式
判断是否已启用Systemd:
ps --no-headers -o comm 1
若返回结果为init
,需要启用Systemd才可以安装Docker
启用Systemd:
sudo echo -e "[boot]\nsystemd=true" | sudo tee -a /etc/wsl.conf
安装Docker:
sudo curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
安装最新版本 Docker-compose(目前为 2.13.0):
sudo curl -L "https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose