普段は Mac を使って開発しているが、最近 Windows ユーザーに開発を教える機会が増えた。そこで Windows での開発環境構築手順を整理した。WSL2 + Ubuntu + Git + VS Code の組み合わせで、Mac と同様の快適な Linux 開発環境が Windows 上に構築できる。仮想マシンよりも軽量で、Windows とのファイル共有もスムーズである。
PowerShell(管理者)で以下を実行:
1wsl --install
再起動を求められた場合は必ず再起動する。
再起動後 PowerShell で:
1wsl -l -v
Ubuntu が表示されない場合は手動インストール:
1wsl --install -d Ubuntu
あるいは Microsoft Store から「Ubuntu」をインストールする。
初回起動時に以下を設定:
これで Ubuntu ターミナルが使用可能になる。
Ubuntu ターミナルで以下を実行:
1sudo apt update
2sudo apt upgrade -y
1sudo apt install -y git
1git config --global user.name "Your Name"
2git config --global user.email "you@example.com"
確認:
1git config --global --list
Windows 側に VS Code をインストールする(公式サイトからダウンロード)。
Remote - WSL を検索Ubuntu ターミナルで:
1code .
VS Code が起動し、左下に WSL: Ubuntu と表示されていれば成功である。
Ubuntu ターミナルで:
1mkdir -p ~/dev
2cd ~/dev
プロジェクトフォルダを作成:
1mkdir myapp
2cd myapp
これがプロジェクトルートとなる。
1cd ~/dev/myapp
2git init
1nano .gitignore
内容例(必要最低限):
# Python
.venv/
__pycache__/
# Node
node_modules/
# VS Code
.vscode/
# OS
.DS_Store
保存:Ctrl + O → Enter 終了:Ctrl + X
1git add .
2git commit -m "first commit"
上記手順により以下が完了する:
~/dev/myapp にプロジェクトディレクトリが用意されている.gitignore を設定し、git init 済み