WSL2安装Linux
CentOS7
安装
- 官方没有提供 CentOS7,可以在下面这个 CentOS-WSL 仓库下载,选择对用的版本下载,也可以使用其他的 CentOS 版本
- 下载完成后解压是两个文件,注意此时放在哪个目录下则会在对应的目录下创建 ext4.vhdx 虚拟磁盘,不建议放到 C 盘,这个文件随着时间增长会变得很大, 双击
CentOS7.exe
即可安装。
YUM 源修改
1 | #mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak |
Ubuntu22.04
安装
在 D://wsl 目录下打开 powershell,执行
1
2
3
4
5
6
7
8
9Invoke-WebRequest -Uri https://wsldownload.azureedge.net/Ubuntu_2004.2020.424.0_x64.appx -OutFile Ubuntu20.04.appx -UseBasicParsing
Rename-Item .\Ubuntu20.04.appx Ubuntu.zip
Expand-Archive .\Ubuntu.zip -Verbose
cd .\Ubuntu\
.\ubuntu2004.exe安装会弹出一个黑框框等几分钟这样,然后输你想要的入用户名和密码就行
root 用户登录
1
2
3wsl --user root
# 修改密码 passwd username
passwd root
换 APT 源
一般是会换成清华源,另外请注意,wsl 的 Ubuntu 证书是过期的,如果你想手动还源的话请记得先更新证书
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#备份原来的源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#编辑源
sudo vim /etc/apt/sources.list
#输入如下
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#再次运行
sudo apt-get update
sudo apt-get upgrade
sudo 免密
sudo adduser user root
sudo visudo
1
2# Append a line
# youruser ALL=(ALL) NOPASSWD:ALL
wsl.conf
执行 vi /etc/wsl.conf 命令创建以文件内容:
1
2
3
4
5
6
7[network]
# 设置虚拟主机的名称,默认的不好看
hostname = ubuntu
[user]
# 启动的默认用户
default = root
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 凉月の博客!
评论