在WSL2中轻松重新安装Ubuntu

简要概述

我正在使用WSL2通过Ubuntu发行版,但有时我想要回到初始状态。
虽然可以通过Windows应用的设置来卸载/重新安装,但每次都需要费心找到正确的设置,所以我总结了使用命令行执行的步骤。

执行步骤 (zhí bù

请使用以下命令卸载Ubuntu发行版本。

C:\Users\yourname>wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.

使用以下命令,安装Ubuntu发行版。

C:\Users\yourname>wsl --install -d Ubuntu
Ubuntu is already installed.
Launching Ubuntu...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: yourname
New password:
Retype new password:
passwd: password updated successfully
The operation completed successfully.
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


This message is shown once a day. To disable it please create the
/home/yourname/.hushlogin file.
yourname@YOURHOST:~$

如果您在WSL2上安装了其他发行版,建议将默认发行版更改回Ubuntu。

C:\Users\yourname>wsl --setdefault Ubuntu
The operation completed successfully.
C:\Users\yourname>wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
docker-desktop-data
docker-desktop

广告
将在 10 秒后关闭
bannerAds