Windows11でLinux(wsl2)を使えるようにしてみた

2025/01/31に公開

対象読者

  • WindowsユーザでLinuxを利用したい人
  • Linux上でしか動作しないソフトウェアを動作させたい人
  • ローカルで無償でコンテナを動かしたい人(Linux上でdocker engineを起動)

環境構築

実行環境

  • OS : Microsoft Windows 11 Pro
  • wsl
    > wsl --version
    WSL バージョン: 2.3.26.0
    カーネル バージョン: 5.15.167.4-1
    WSLg バージョン: 1.0.65
    MSRDC バージョン: 1.2.5620
    Direct3D バージョン: 1.611.1-81528511
    DXCore バージョン: 10.0.26100.1-240331-1435.ge-release
    Windows バージョン: 10.0.26100.3037
    

Linux(Ubuntu) のインストール

  • 管理者権限でPowershellを起動

  • インストールするLinuxの種類を確認
    結構種類選べます。デフォルトはUbuntu

    > wsl --list --online
    インストールできる有効なディストリビューションの一覧を次に示します。
    '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.6              openSUSE Leap 15.6
    SUSE-Linux-Enterprise-15-SP5    SUSE Linux Enterprise 15 SP5
    SUSE-Linux-Enterprise-15-SP6    SUSE Linux Enterprise 15 SP6
    openSUSE-Tumbleweed             openSUSE Tumbleweed
    
  • インストールコマンドを実行(今回はフォルトのUbuntuで)

    > wsl --install
    
  • インストールが自動で開始される

    > wsl --install
    ダウンロード中: Linux 用 Windows サブシステム 2.3.26
    インストール中: Linux 用 Windows サブシステム 2.3.26
    Linux 用 Windows サブシステム 2.3.26 はインストールされました。
    Windows オプション コンポーネントをインストールしています: VirtualMachinePlatform
    
    展開イメージのサービスと管理ツール
    バージョン: 10.0.26100.1150
    
    イメージのバージョン: 10.0.26100.2894
    
    機能を有効にしています
    [==========================100.0%==========================]
    操作は正常に完了しました。
    要求された操作は正常に終了しました。変更を有効にするには、システムを再起動する必要があります。
    インストール中: Ubuntu
    Ubuntu がインストールされました。
    要求された操作は正常に終了しました。変更を有効にするには、システムを再起動する必要があります。
    
  • 指示に従い、再起動を実施 ※コマンド実行するとすぐに再起動かかるので注意!

    > shutdown -r -t 0
    
  • インストールされていることを確認

Linux(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: testuser01
    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.1 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
    
    * Documentation:  https://help.ubuntu.com
    * Management:     https://landscape.canonical.com
    * Support:        https://ubuntu.com/pro
    
    System information as of Fri Jan 31 16:47:35 JST 2025
    
    System load:  0.71                Processes:             32
    Usage of /:   0.1% of 1006.85GB   Users logged in:       0
    Memory usage: 6%                  IPv4 address for eth0: 172.29.146.41
    Swap usage:   0%
    
    
    This message is shown once a day. To disable it please create the
    /home/testuser01/.hushlogin file.
    testuser01@hogehoge:~$
    

とりあえずここまで

Discussion