1 安装wsl2
- 官方文档:https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-2---check-requirements-for-running-wsl-2
- 步骤
- windows开启wsl子系统功能,以管理员身份打开powershell,执行:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- 开启虚拟机平台,以管理员身份打开powershell,执行:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- 重启电脑
- 设置wsl2为默认版本:
wsl --set-default-version2
- 列出可用发行版,powershell中执行:
wsl -l -o
- 下载并安装指定版本的Linux,powershell中执行:
wsl --install -d <Distribution>
- 在Windows Terminal中配置Ubuntu,打开setting.json文件,在"profiles"项目找到 "Ubuntu", 设置hidden=false
2 修改root密码
- 以管理员打开powershell,执行:
Ubuntu config --default-user root
- 打开ubuntu(默认是root账户),执行:
passwd
,输入两次密码,即可修改root密码 - 以管理员打开powershell,执行:
Ubuntu config --default-user 默认用户名
3 换源 Ubuntu22.04
- 备份源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
- 修改源:sudo vim /etc/apt/sources.list
- 清华
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
- 阿里云
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
3. sudo apt update && sudo apt upgrade -y
4 Ubuntu系统从C盘迁移到D盘
以管理员在powershell中执行
- 导出到D盘:
wsl --export Ubuntu d:ubuntu2204ubuntu.tar
- 从C盘中注销原始的ubuntu系统:
wsl --unregister Ubuntu
- 从D盘中重新导入:
wsl --import Ubuntu d:ubuntu2204 d:ubuntu2204ubuntu.tar
5 安装docker
curl -fsSL [https://get.docker.com](https://get.docker.com) -o get-docker.sh
sudo sh get-docker.sh
rm get-docker.sh
sudo service docker start
service docker status
ps aux|grep docker
sudo docker run hello-world