(1)在搜索栏搜索“启用或者关闭windows功能”。
(2)选择“Hyper-V"、"(Virtual Machine Platform)"与 “适用于Linux的Windows子系统虚拟机平台”。
(3)立即重启”(或者自己手动重启)。
wsl --list --online
wsl --install -d Ubuntu-24.04
wsl --list --verbose
wsl --export Ubuntu-24.04 D: empubuntu.tar
wsl --unregister Ubuntu-24.04
wsl --import Ubuntu-24.04 D:kaifagongjuwslUbuntu_1 D: empubuntu.tar --version 2
wsl --set-default Ubuntu-24.04
Remove-Item D: empubuntu.tar
###========== 验证WSL安装位置 ==========
Write-Host “`n[1] 目录文件列表:” -ForegroundColor Green
Get-ChildItem “D:kaifagongjuwslUbuntu_1” -Force |
Format-Table Name, @{N=‘Size(MB)’;E={[math]::Round($_.Length/1MB,2)}}, LastWriteTime
Write-Host “`n[2] 注册表中的WSL配置:” -ForegroundColor Green
Get-ChildItem “HKCU:SoftwareMicrosoftWindowsCurrentVersionLxss” |
ForEach-Object {
$props = Get-ItemProperty .PSPathif(_.PSPath
if (.PSPathif(props.BasePath -like “Ubuntu_1”) {
Write-Host " ✓ 找到匹配的WSL!" -ForegroundColor Green
Write-Host " 发行版名称: (((props.DistributionName)" -ForegroundColor Cyan
Write-Host " 安装路径: (((props.BasePath)" -ForegroundColor Cyan
Write-Host " 默认用户ID: (((props.DefaultUid)" -ForegroundColor Gray
}
}
========================================================
安装多版本与上面一样 只不过导出 、导入 文件名字变更一下
wsl --shutdown
导出Ubuntu(先手动创建这个文件夹)
wsl --export Ubuntu-24.04 D: empubuntu.tar
导入到指定位置
wsl --import Ubuntu-24.04-er D:kaifagongjuwslUbuntu_2 D: empubuntu.tar --version 2
查看已安装的WSL发行版
wsl --list --verbose
删除临时文件
Remove-Item D: empubuntu.tar
重复上面的步骤