WSL 2 รัน Linux Kernel จริงบน Windows ประสิทธิภาพดีกว่า WSL 1 รองรับ GUI Apps, System Calls เร็วขึ้น, File I/O ดีกว่า
ขั้นตอนการติดตั้ง
Step 1: เปิด WSL Feature
- Start → ค้นหา "Turn Windows Features On or Off"
- ติ๊ก: Windows Subsystem for Linux + Virtual Machine Platform
- OK → Restart Now
Step 2: ติดตั้ง WSL 2 Kernel Update
- ดาวน์โหลด: WSL 2 Linux Kernel Update Package
- ติดตั้ง .msi ตามปกติ
- PowerShell/CMD (Admin):
wsl --set-default-version 2
Step 3: ติดตั้ง Linux Distro
ทาง Microsoft Store (ง่าย): Search "Ubuntu" → Get
ทาง Command Line:
wsl --list --online # ดู Distro ที่มี
wsl --install -d Ubuntu # ติดตั้ง Ubuntu (Default)
Step 4: สลับ Distro เดิมให้เป็น WSL 2 (ถ้ายังเป็น v1)
wsl -l -v # ดู Version ปัจจุบัน
wsl --set-version Ubuntu 2 # สลับเป็น v2 (ใช้เวลาสักครู่)
wsl -l -v # Verify
หลังติดตั้งเสร็จ
- Start → "Ubuntu" → รัน Terminal Linux
- ครั้งแรก: ตั้ง Username/Password
- รัน Linux Commands, apt, docker (ใน WSL 2) ได้เลย
WSL 2 vs VirtualBox/VMware
| Feature | WSL 2 | VM (VirtualBox/VMware) |
|---|---|---|
| Integration | Deep (Windows ↔ Linux) | Isolated |
| GUI Apps | รองรับ (WSLg) | Full Desktop |
| Distro Choices | จำกัด (Store/Import) | ทุก Distro |
| Performance | ดีมาก (Near Native) | Overhead สูงกว่า |
| Use Case | Dev, CLI, Containers | Full OS, Kernel Dev, GUI Heavy |