はじめに

新しいPCを購入したので、開発環境を一から構築する必要がある。
まずは、WSLをインストールしたいのでその時の記録を残しておく。

環境

1
Windows 11 Professional

WSLのインストール

PowerShellを起動し、下記を実行する。

1
wsl --install
ログ
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
wsl --install
インストール中: Ubuntu
Ubuntu がインストールされました。
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: kbushi
New password:
Retype new password:
passwd: password updated 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.3 LTS (GNU/Linux 5.15.153.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/kbushi/.hushlogin file.
kbushi@kbushi:~$

インストールされたディストリビューションの確認

1
cat /etc/os-release
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
kbushi@kbushi:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Ubuntu 22.04.03 LTSがインストールされている。

Ubuntu24.04 を インストールする

Ubuntu 24.04 を使いたいのでインストールする。

利用可能なディストリビューションの確認

1
wsl --list --online
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
インストールできる有効なディストリビューションの一覧を次に示します。
'wsl.exe --install <Distro>' を使用してインストールします。

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
Ubuntu-24.04                           Ubuntu 24.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

現状では上記のディストリビューションが使用できるようだ。
Ubuntu-24.04 は利用可能なディストリビューションとして存在するのでインストールする。

Ubuntu24.04をインストールする

1
wsl --install -d Ubuntu-24.04
ログ
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
wsl --install -d Ubuntu-24.04
インストール中: Ubuntu 24.04 LTS
Ubuntu 24.04 LTS がインストールされました。
Ubuntu 24.04 LTS を起動しています...
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: kbushi
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 24.04 LTS (GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64)

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

 System information as of Sat Jul 20 16:59:03 JST 2024

  System load:  0.09                Processes:             28
  Usage of /:   0.1% of 1006.85GB   Users logged in:       0
  Memory usage: 2%                  IPv4 address for eth0: 172.19.126.2
  Swap usage:   0%


This message is shown once a day. To disable it please create the
/home/kbushi/.hushlogin file.

これでインストールは完了。

あとは、WSLを起動した際の既定のディストリビューションを変更し、Ubuntu22.04はアンインストールする。

既定のディストリビューションの変更

Ubuntu24.04を既定のディストリビューションとする。

1
2
3
4
5
6
wsl --list

Linux  Windows サブシステム ディストリビューション:
docker-desktop (既定)
Ubuntu
Ubuntu-24.04
1
wsl --set-default Ubuntu-24.04
1
2
3
4
5
6
wsl --list

Linux  Windows サブシステム ディストリビューション:
Ubuntu-24.04 (既定)
docker-desktop
Ubuntu

Ubuntu-24.04が既定となっているのでOK

不要なディストリビューションを削除する

https://learn.microsoft.com/ja-jp/windows/wsl/basic-commands#unregister-or-uninstall-a-linux-distribution

1
wsl --unregister Ubuntu
1
2
3
4
5
wsl --list

Linux  Windows サブシステム ディストリビューション:
Ubuntu-24.04 (既定)
docker-desktop

初期セットアップ

MicroSoftで設定のべストプラクティスがあるので、これをやっておこう。
https://learn.microsoft.com/ja-jp/windows/wsl/setup/environment

はじめにLinux のユーザー名とパスワードを設定する はできている。

パッケージの更新とアップグレード

WSLを立ち上げ、下記コマンドを実行する。

1
sudo apt update && sudo apt upgrade
ログ
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# OpenSSH CVE-2024-6387 fix is available for all affected Ubuntu releases.
# RegreSSHion: Possible RCE Due To A Race Condition In Signal Handling.
# For more details see: https://ubuntu.com/blog/ubuntu-regresshion-security-fix
#
The following packages will be upgraded:
  apparmor apport apport-core-dump-handler cloud-init curl dhcpcd-base distro-info-data gir1.2-glib-2.0
  git git-man gtk-update-icon-cache landscape-client landscape-common less libapparmor1 libc-bin libc6
  libcups2t64 libcurl3t64-gnutls libcurl4t64 libegl-mesa0 libgbm1 libgdk-pixbuf-2.0-0 libgdk-pixbuf2.0-bin
  libgdk-pixbuf2.0-common libgl1-mesa-dri libglapi-mesa libglib2.0-0t64 libglib2.0-bin libglib2.0-data
  libglx-mesa0 libgnutls30t64 libgtk-3-0t64 libgtk-3-bin libgtk-3-common libnetplan1 libnghttp2-14
  libnss-systemd libpam-modules libpam-modules-bin libpam-runtime libpam-systemd libpam0g libssl3t64
  libsystemd-shared libsystemd0 libtiff6 libudev1 locales mesa-vulkan-drivers netplan-generator netplan.io
  openssh-client openssl python3-apport python3-cryptography python3-distupgrade python3-idna
  python3-jinja2 python3-netplan python3-problem-report snapd systemd systemd-dev systemd-resolved
  systemd-sysv systemd-timesyncd tzdata ubuntu-pro-client ubuntu-pro-client-l10n
  ubuntu-release-upgrader-core udev vim vim-common vim-runtime vim-tiny wget wsl-setup xkb-data xxd
80 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
36 standard LTS security updates
Need to get 98.4 MB of archives.
After this operation, 3366 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

上記が更新される。

他の作業についてはそのツールを使うときに試してみることにする。

参考

おわりに

ほかにもいろいろセットアップするものがあるので粛々とやっていく。