前置:
控制面板—程序—程序与功能 勾选 适用于Linux的Windows子系统 和 虚拟机平台(随后重启)
之后如果出现 由于未安装所需的特性,无法启动操作。 错误代码: Wsl/InstallDistro/Service/RegisterDistro/CreateVm/HCS/HCS_E_SERVICE_NOT_AVAILABLE
是由于虚拟机平台未成功打开,可 以管理员身份 打开 PowerShell
执行以下命令:
1
2
3
4
5
6
7
8
# 启用 WSL 功能
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# 启用虚拟机平台
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 启用 Hyper-V(部分系统需要)
dism.exe /online /enable-feature /featurename:Hyper-V /all /norestart
安装过程:
1
2
3
4
wsl --install 该步骤需要输入 用户名 和两次相同密码
wsl --list --verbose 可以查看可用的linux发行版
wsl --install Ubuntuxxx 选择发行版安装
wsl 启动wsl
验证安装:
1
2
wsl --status
wsl --list --verbose
注意事项:
在第二步查看可用发行版时,容易出现 无法从“https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json”提取列表分发。无法解析服务器的名称或地址 错误代码: Wsl/WININET_E_NAME_NOT_RESOLVED
该问题,主要问题在于DNS污染,由于每次域名访问网站时会先查询本机的DNS,因此修改本机hosts文件即可,具体过程如下:
1 raw.githubusercontent.com - GitHub · Build and ship software on a single, collaborative platform · GitHub该网站中可查询最新可用的raw.githubusercontent.com
de ipv4地址
2 以管理员权限打开本机hosts文件(一般位置在C:\Windows\System32\drivers\etc
),文件最后加上 IP地址 raw.githubusercontent.com
即可,无需重启。
额外操作:
1 vscode
安装插件wsl
,能够更方便的进行项目开发。
2 wsl默认安装到C盘,该方案可以迁移至其它盘WSL默认安装目录 - CharyGao - 博客园。
推荐文章:
1 无法访问https://raw.githubusercontent.com/xx的解决方案(2025.2亲测有效)_raw.githubusercontent com-CSDN博客