The Ultimate WSL2 Configuration Guide for Developers
WSL2 gives Windows developers a real Linux kernel and a practical environment for software development, containers, automation and GPU computing. But its defaults are not necessarily ideal for a workstation that also runs Windows applications, local language models and development servers.
After working with Ubuntu under WSL2, moving its virtual disk to another drive and evaluating resource-heavy inference workloads, I found that tuning WSL is mostly about managing boundaries: how much memory Linux can consume, where its files live, and how it communicates with the host and network.
1. Know which configuration file to edit
%USERPROFILE%\.wslconfig lives on Windows and controls the WSL2 virtual machine globally. /etc/wsl.conf lives inside a particular Linux distribution and controls distribution-specific behavior, such as its default user, interoperability and systemd settings.
Open PowerShell and check the installed WSL version:
wsl --version
wsl --status
wsl --list --verbose
notepad "$env:USERPROFILE\.wslconfig"
Here is a starting configuration for a memory-intensive workstation with enough physical RAM to leave substantial headroom for Windows. My own evaluation used a 56 GB limit.
[wsl2]
memory=56GB
swap=8GB
localhostForwarding=true
[experimental]
autoMemoryReclaim=gradual
The memory value is a ceiling, not permanently dedicated RAM. Set it to suit your machine; a 56 GB ceiling is unsuitable for a 32 GB host. Swap can prevent some out-of-memory failures, but sustained swapping is especially undesirable for model inference. Omit processors unless you need to limit CPU consumption; for a shared Windows/Linux workstation, setting it can preserve host responsiveness.
Save your work before applying changes, because this command stops WSL distributions and their processes:
wsl --shutdown
Restart Ubuntu and verify with free -h, nproc and swapon --show.
2. Keep Linux-heavy workloads on the Linux filesystem
WSL mounts Windows drives under /mnt/c, /mnt/d, and similar paths. This is convenient for exchanging files but can be slower for metadata-intensive workloads such as node_modules, Git operations or builds.
For Linux development, I prefer a repository under ~/projects and open it from Windows via WSL-aware tools. Large model files benefit from benchmarking their actual storage location rather than assuming that every file access will be faster inside the virtual disk. The underlying physical SSD still sets limits.
A distribution's ext4 virtual disk can live on a secondary drive. Check both Linux free space (df -h /) and the physical Windows drive's available capacity: a growing VHDX can run the host out of space.
3. Configure networking deliberately
Default NAT networking typically allows Windows to reach a Linux service through localhost forwarding. For instance, a development server in Ubuntu on port 3000 can usually be opened from Windows at http://localhost:3000.
That is not the same as granting other computers access. On supported Windows 11 versions, mirrored networking is an alternative:
[wsl2]
networkingMode=mirrored
With mirrored mode, localhost forwarding is not the setting that controls connectivity. Check Windows and Hyper-V firewall rules and the application's listen address. Expose only the required ports to trusted hosts; don't bind unauthenticated AI or development services to every interface unnecessarily.
For outbound connections from WSL to another machine, test the address and hostname separately:
ip route
getent hosts lab-pc.local
curl --connect-timeout 5 http://192.0.2.10:8080/health
Replace the documentation IP and hostname with the actual LAN values. If the IP works but the name fails, troubleshoot DNS or local name resolution rather than rebuilding networking.
4. Use native Linux developer tools
Windows PATH entries can leak into WSL. A Windows npm installation may accidentally be selected when you expect a Linux executable. Diagnose this with:
type -a node npm codex
node -p 'process.platform'
printf '%s\n' "$PATH" | tr ':' '\n'
nvidia-smi
Use native Linux Node.js and package installations for Linux projects. GPU workloads require a compatible Windows GPU driver and the corresponding WSL-supported runtime; do not install a conventional Linux display driver blindly inside WSL.
5. Measure before and after
Record build time, peak memory, disk latency and application responsiveness before making changes. Change one setting at a time. WSL configuration is not a contest to maximize every resource allocation; the goal is to let Linux and Windows coexist without contention.
