WSL2 セットアップガイド

WSL2 とは

Windows上でLinux(Ubuntu等)を動かす仕組み。Windowsを再起動せずにLinuxコマンドが使える。

仮想マシンではなく、WindowsとLinuxが同時に動くイメージ。ファイル共有も可能。

インストール

1. PowerShell(管理者)を開く
wsl --install
2. PCを再起動
3. ユーザー名・パスワードを設定
デフォルトでUbuntu 24.04が入る。他のディストリビューションも可能: wsl --install -d Debian

基本コマンド

WSL起動
wsl
Windows側からLinuxのファイルにアクセス
\\wsl.localhost\Ubuntu\home\ユーザー名\
Linux側からWindowsのファイルにアクセス
/mnt/c/Users/ユーザー名/
WSLの状態確認
wsl --status
WSLのシャットダウン
wsl --shutdown

初期設定(推奨)

パッケージ更新
sudo apt update && sudo apt upgrade -y
Git設定
git config --global user.name "名前"
git config --global user.email "email@example.com"
Node.js(fnm経由)
curl -fsSL https://fnm.vercel.app/install | bash
fnm install 22 && fnm default 22
Python
sudo apt install python3 python3-pip -y

つまずきポイント

症状対処
wslコマンドがないWindows Update → 再起動 → 再インストール
画面閉じるとWSLが終了するWindows設定 → 電源 → カバー閉じても「何もしない」
Windowsからのパスが長いエクスプローラーのアドレス欄に \\wsl$ と入力
メモリ使用量が多い%UserProfile%\.wslconfig で制限設定

.wslconfig の例

%UserProfile%\.wslconfig(Windows側)
[wsl2]
memory=8GB
processors=4
swap=4GB
← ガイド一覧に戻る