WSL2 Setup on Windows
Guide to setting up and tuning WSL2 on Windows 11 for development: install, .wslconfig resource limits, Windows Terminal/VS Code integration, and GPU passthrough.
WSL2 (Windows Subsystem for Linux 2) runs a real Linux kernel inside a Hyper-V VM. You get a Linux dev environment without leaving Windows. Setup is one command. Making it fast takes some tuning.
Setup flow
Steps
- Enable WSL2 and install a distro. Run
wsl --installin an administrator PowerShell. This turns on the WSL and Virtual Machine Platform features, sets WSL 2 as default, and installs Ubuntu. Restart when prompted. - Create your Linux user. On first launch, set a username/password; this account gets
sudoautomatically and is specific to that distro. - Pick a different distro if you want one.
wsl --list --onlineto see options,wsl --install -d Debianto add one,wsl --set-default <DistroName>to switch the default. - Configure
.wslconfigat%USERPROFILE%\.wslconfigto bound VM resources:
A good rule for memory is host RAM minus 8GB. Apply changes with[wsl2] memory=24GB processors=8 networkingMode=mirrored dnsTunneling=true firewall=true localhostForwarding=truewsl --shutdown(closing the terminal window is not enough). - Enable systemd in
/etc/wsl.confinside the distro:
Docker, Tailscale, and snapd all depend on systemd being active.[boot] systemd=true - Install Windows Terminal (Microsoft Store), it auto-creates a profile per WSL distro.
- Install VS Code’s “Remote - WSL” extension so
code .from inside Linux opens a fully remote-aware editor window. - Keep project files inside the WSL filesystem (e.g.
~/projects), not under/mnt/c/.... Access them from Windows Explorer via\\wsl$\<DistroName>\home\<User>if needed. - GPU passthrough (optional, for AI workloads): install only the CUDA Toolkit inside WSL (never the Linux GPU driver, which comes from Windows via GPU-PV). Verify with
nvidia-smiinside the distro.
Tips
networkingMode=mirrored(Windows 11 22H2+) speeds up WSL2 networking from ~3 Mbps to near-native speed. Set it by default.- Exclude the WSL VHDX, Docker data, and
~/projectsfrom Windows Defender real-time scanning. Without this, I/O can be 10-50x slower. - Use version managers inside WSL (
pyenv,fnm) rather than installing Python/Node globally. - Mount extra drives via
/etc/fstabwith Virtio-FS/9p rather than reaching across/mnt/c/.
Common pitfalls
- Working from
/mnt/c/:node_modules,.git, and build artifacts there makegit status/npm install/builds 10-50x slower. Move the project into the Linux filesystem. - Installing the full
nvidia-cudameta-package instead ofcuda-toolkit-13-x, breaks the driver stubs. GPU drivers only come through Windows. - Forgetting
systemd=true: Docker/Tailscale/snapd silently fail to start. - Third-party firewalls/AV (Kaspersky, AVG, Avast, Symantec) have been reported to block WSL networking outright.
.wslconfigchanges not applying: a plain terminal close doesn’t restart the VM; runwsl --shutdownfirst.- On a Windows 11 build older than 22H2,
networkingMode=mirroredcauses network isolation failures. Check your build withwinver.
Related
Sources
- How to install Linux on Windows with WSL
- Set up a WSL development environment
- FAQ’s about Windows Subsystem for Linux
- Configuring .wslconfig and wsl.conf in WSL: a complete guide
- WSL2 Complete Setup & Optimization Guide for Windows 11 Developers (2025/2026)
- Enabling GPU in WSL2 for ML and CUDA: A Complete Guide