本文距离上次更新已过去 0 天,部分内容可能已经过时,请注意甄别。
https://github.com/wsldl-pg/CentWSL
https://github.com/mishamosher/CentOS-WSL
https://github.com/yosukes-dev/RHWSL
先决条件
必须运行 Windows 10 版本 2004 及更高版本(内部版本 19041 及更高版本)或 Windows 11,检查 Windows 版本及内部版本号:按 Windows 徽标键 + R,然后键入“winver”,选择“确定”
需要在BIOS中开启虚拟化技术,检查是否启用虚拟化:同时按住 CTRL、Shift 和 ESC 键打开任务管理器,选择“性能”>“CPU”
启用 Windows 子系统:“控制面板”>“程序和功能”>“启用或关闭 Windows 功能”>勾选“适用于 Linux 的 Windows 子系统”
WSL 的基本命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| wsl --install
wsl --update
wsl -l -v
wsl --status
wsl --shutdown
|
设置WSL的默认版本
1 2 3
| wsl --set-default-version <Version>
|
设置默认 Linux 发行版
1 2 3
| wsl --set-default <DistributionName>
|
要设置与 wsl 命令一起使用的默认 Linux 发行版
1 2
| wsl --setdefault <DistributionName>
|
将 WSL 版本设置为 1 或 2
1 2 3 4
| wsl --set-version <DistributionName> <Version>
|
更改发行版的默认用户
1 2 3
| <DistributionName> config --default-user <Username>
|
其他命令
1 2 3 4 5 6 7 8 9 10 11 12 13
| net stop LxssManager
wsl --terminate <DistributionName>
wsl --unregister <DistributionName>
wsl --export <DistributionName> <镜像存放路径>
|
由于是最小安装,一些常用的命令没有,无法使用,可以使用 yum 命令进行安装,以方便使用
1 2 3 4 5 6 7
| yum -y update yum -y install gcc gcc-c++ make wget yum -y install openssh-clients openssh-server yum -y install vim yum -y install tar yum -y install net-tools yum -y install ncurses
|
解决 Centos8 yum 官方源下线后无法使用问题
# 进入配置文件夹
mv /etc/yum.repos.d/ /etc/yum.repos.d_bak && mkdir /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 如果你没有安装wget,也可以用下面命令
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 运行 dnf makecache 生成缓存
dnf makecache