Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

Windows 11 WSL2 のインストール

0
Posted at

はじめに

備忘録です。WSL2 をインストールします。

環境

WSL2 とは

WSL2 (Windows Subsystem for Linux 2) は Windows 上で Linux 環境を実行するための Microsoft 公式機能です。

WSL2 のインストール

PowerShell を「管理者として実行」し、下記のコマンドを実行します。

PowerShell
wsl --install

インストールが開始します。完了するまで少し待ちます。

インストールが完了しました。

メッセージに従い、以下のコマンドを実行して起動します。

PowerShell
wsl.exe -d Ubuntu

WSL2 (Ubuntu) が起動すると、初期ユーザーアカウントの作成を求められます。今回は user で設定しました。

次にパスワードも求められるので、入力します。パスワードは入力しても画面には表示されませんので、注意してください。今回はユーザーアカウントと同じく user にしました。これでインストールは完了です。

WSL2 の動作確認

今後は以下のコマンドで WSL2 の起動や確認が行えます。

PowerShell
# デフォルトの Linux ディストリビューションを起動する。
wsl
PowerShell
# 指定した Linux ディストリビューションを起動する。
# ロングオプションは「wsl.exe --distribution Ubuntu」。
wsl.exe -d Ubuntu
PowerShell
# インストールされている Linux ディストリビューションの一覧と状態を表示する。
# ロングオプションは「wsl --list --verbose」。
wsl -l -v

テストのため、起動した WSL2 に対して適当なコマンドを実行します。

Bash
# Linux カーネルのバージョンを表示する。
uname -r
Bash
# Linux ディストリビューションの情報を表示する。
# ※ 既定では Ubuntu がインストールされる仕様になっている。変更可能。
lsb_release -a

以下のような実行結果が表示されます。

Ubuntu パッケージの更新

Ubuntu の場合、以下のコマンドを実行すると、パッケージの確認や更新が行えます。特に理由がなければ、実行しておきましょう。

Bash
# パッケージの更新情報を取得する。
sudo apt update
Bash
# パッケージを実際に更新する。
sudo apt upgrade

おわりに

Windows 上で Linux 環境を手軽に使えるので便利です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?