LoginSignup
3
1

WSL2でUbuntuの再インストールを簡単に行う

Posted at

概要

WSL2でUbuntuディストリビューションを利用していますが、まっさらな状態に戻したい時があります。
Windowsアプリの設定からアンインストール/再インストールすればよいのですが、毎回「どこの設定だったかな?」と探すのが面倒だったので、コマンドラインで実行する手順をまとめました。

実行手順

以下のコマンドで、Ubuntuディストリビューションのアンインストールします。

Ubuntuディストリビューションのアンインストール
C:\Users\yourname>wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.

以下のコマンドで、Ubuntuディストリビューションのインストールします。

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

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1