1升级powershell后才能安装WSL2--最后安装linux--Ubuntu 22.04.3 LTS

发布于:2024-03-23 ⋅ 阅读:(55) ⋅ 点赞:(0)

视频

https://www.bilibili.com/video/BV1uH4y1W7UX

特殊开启–Hyper-V虚拟机

把一下代码保存到【a.bat】的执行文件中,进行Hyper-V虚拟机的安装开启【Windows 批处理文件 (.bat)】

pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL

查看电脑本版
请添加图片描述

步骤1:使用 Winget 方式安装 PowerShell

查看是否能更新PowerShell–

winget search Microsoft.PowerShell

查看结果为

名称       ID                           版本    源
-------------------------------------------------------
PowerShell Microsoft.PowerShell         7.3.1.0 winget
PowerShell Microsoft.PowerShell.Preview 7.4.1.0 winget
PS C:\WINDOWS\system32>

执行更新

winget install --id Microsoft.Powershell --source winget

2新旧版本的powershell

请添加图片描述

请添加图片描述

步骤 3- 启用虚拟机功能

安装 WSL 2 之前,必须启用“虚拟机平台”可选功能。 计算机需要虚拟化功能才能使用此功能。

以管理员身份打开 【旧版本的】PowerShell 并运行:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

PS C:\WINDOWS\system32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Deployment Image Servicing and Management tool
Version: 10.0.22621.2792

Image Version: 10.0.22621.3296

启用一个或多个功能
[==========================100.0%==========================]
The operation completed successfully.
PS C:\WINDOWS\system32>

4下载wsl2的安装包

https://learn.microsoft.com/zh-cn/windows/wsl/install-manual

请添加图片描述

重启

步骤 5 列出已安装的 Linux 发行版【只能使用新版本的powershell】

wsl --list --verbose
wsl --status
wsl --version

旧版本的爆出错误

请添加图片描述

wsl : The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
pelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wsl --list --verbose
+ ~~~
    + CategoryInfo          : ObjectNotFound: (wsl:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\WINDOWS\system32> wsl2 --list --verbose
wsl2 : The term 'wsl2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
 spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wsl2 --list --verbose
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (wsl2:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

步骤 6 重启计算机

打开【新版本】的Powershell
请添加图片描述

查看可以安装的linux子系统【查看命令】

wsl --install

查看命令

wsl --list --online
PS C:\Users\luich> wsl --list --online
以下是可安装的有效分发的列表。
请使用“wsl --install -d <分发>”安装。

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed
PS C:\Users\luich>

安装某个版本的Ubuntu

wsl --install -d <DistroName>
我需要下载Ubuntu-22.04
wsl --install -d Ubuntu-22.04

请添加图片描述

用户名:luichun
密码:xxxxxxx

请添加图片描述

显示安装

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到