Introduction
WSL for Windows
Windows Subsystem for Linux (WSL) lets you run a real Linux environment directly inside Windows — no virtual machine, no dual boot. For web development, it's the recommended setup for Windows users.
สำหรับ Windows users เท่านั้น
ถ้าคุณใช้ macOS หรือ Linux อยู่แล้ว ข้ามหน้านี้ไปได้เลย
What is WSL and why use it?
Most web development tools, tutorials, and deployment servers are built for Linux or macOS. When you follow a tutorial on Windows without WSL, you'll often hit small differences — file path formats, missing commands, or tools that behave differently — that slow you down and cause confusing errors.
WSL solves this by giving you a full Ubuntu Linux environment inside Windows. You get:
- The same terminal commands used in every tutorial (
ls,cd,mkdir,touch) - Node.js, npm, and Git behaving identically to macOS and Linux
- A filesystem that's fast and compatible with all dev tools
- VS Code integration that feels completely native
WSL ไม่ใช่ Virtual Machine
WSL ทำงานโดยตรงใน Windows ไม่ต้องบูตแยก ไม่ช้า และไม่กินทรัพยากรเครื่องมากเหมือน Virtual Machine ทั่วไป เปิดปิดได้เหมือน Terminal ปกติ
1. Enable WSL via PowerShell
Open PowerShell as Administrator — right-click the Start menu and choose "Windows PowerShell (Admin)" or "Terminal (Admin)".
Run this single command:
wsl --installThis enables WSL, installs the latest WSL 2 kernel, and installs Ubuntu by default. When it finishes, restart your computer.
ต้องใช้ Windows 10 version 2004 ขึ้นไป หรือ Windows 11
ตรวจสอบ Windows version โดยกด Win+R พิมพ์ winver แล้วกด Enter ถ้าเวอร์ชันเก่ากว่า 2004 (build 19041) ให้อัปเดต Windows ก่อน
If you already have WSL installed and want to check the version:
wsl --versionwsl --list --verbose2. Install Ubuntu from the Microsoft Store
After restarting, Ubuntu should open automatically and begin installing. If it doesn't, search for "Ubuntu" in the Microsoft Store and click Get.
Once Ubuntu is installed, launch it from the Start menu. The first launch will take a minute to set up the filesystem.
แนะนำให้ใช้ Ubuntu 22.04 LTS หรือ 24.04 LTS
ในหน้า Microsoft Store จะมีหลายเวอร์ชัน แนะนำให้เลือก Ubuntu 22.04 LTS หรือ 24.04 LTS เพราะเสถียรและมี support ระยะยาว
3. Set up your username and password
The first time Ubuntu runs, it will ask you to create a Linux username and password.
Enter new UNIX username: johnNew password:Retype new password:passwd: password updated successfullyA few things to know:
- The username can be anything — it doesn't need to match your Windows username
- When typing your password, nothing will appear on screen — this is normal, just type and press Enter
- This password is used when running
sudocommands (administrator actions in Linux)
อย่าลืมรหัสผ่าน WSL ของคุณ
รหัสผ่านนี้จะถูกขอทุกครั้งที่ใช้คำสั่ง sudo ถ้าลืมรหัสผ่านสามารถ reset ได้แต่ยุ่งยาก ควรจดบันทึกเอาไว้
After setup, update the package list and upgrade pre-installed packages:
sudo apt update && sudo apt upgrade -y4. Basic WSL commands to know
Your Ubuntu terminal works like any Linux terminal. Here are the commands you'll use most:
pwd # show current directoryls # list filesls -la # list all files including hidden onescd ~ # go to your home directorycd projects # enter a foldermkdir my-app # create a new foldertouch index.js # create a new fileclear # clear the terminal screenInstall Node.js via nvm
Always install Node.js via nvm (Node Version Manager) inside WSL — it avoids permission issues and lets you switch Node versions easily.
# Install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash# Close and reopen your terminal, then install Node.js LTSnvm install --ltsnvm use --lts# Verifynode --versionnpm --versionทำไมต้องใช้ nvm แทน apt install nodejs?
Node.js จาก apt มักจะเป็นเวอร์ชันเก่ามาก และอาจเกิดปัญหาสิทธิ์เข้าถึงตอนติดตั้ง npm packages แบบ global nvm แก้ปัญหาทั้งสองข้อนี้และยังทำให้เปลี่ยน Node version ได้ง่ายด้วย
5. Open WSL in VS Code
Install the WSL extension in VS Code (ms-vscode-remote.remote-wsl). Search for "WSL" in the Extensions panel and click Install.
Once installed, open your WSL terminal, navigate to your project folder, then launch VS Code with:
code .VS Code will open with a green "WSL: Ubuntu" badge in the bottom-left corner, confirming it's connected to your Linux environment. The integrated terminal inside VS Code will also be your WSL terminal.
VS Code Server
ครั้งแรกที่รัน code . จาก WSL จะมีการดาวน์โหลด VS Code Server เข้าไปใน WSL โดยอัตโนมัติ รอสักครู่แล้วจะเปิด VS Code ขึ้นมาเอง ครั้งต่อไปจะเร็วขึ้น
6. Always store project files inside WSL
This is the most important rule when using WSL: keep your project files inside the WSL filesystem, not on your Windows drive.
# Good — inside WSL filesystem (fast)~/projects/my-app# Bad — on the Windows C: drive mounted into WSL (slow)/mnt/c/Users/John/Documents/my-appStoring files on /mnt/c/ works but is significantly slower because every file operation crosses the WSL/Windows boundary. Tools like npm install can take 5–10x longer.
Create a projects folder in your WSL home directory and keep everything there:
mkdir ~/projectscd ~/projectsAccessing WSL files from Windows Explorer
You can browse your WSL files in Windows Explorer by typing this in the address bar:
\\wsl$\UbuntuOr run explorer.exe . from any WSL directory to open that folder directly in Explorer.
อย่าแก้ไขไฟล์ WSL ผ่าน Windows apps โดยตรง
การแก้ไขไฟล์ใน WSL filesystem ผ่าน Windows applications (เช่น Notepad) อาจทำให้ line endings และ permissions เสียหายได้ ควรใช้ VS Code ที่เชื่อมต่อผ่าน Remote WSL เสมอ