Shell - Windows Subsystem for Linux (WSL)¶
Setup and configuration guide for Windows Subsystem for Linux.
Overview¶
WSL enables running a Linux environment directly on Windows, providing a native Linux development experience without dual-boot or virtualization overhead. This is essential for developers using Windows who want access to Unix tools and workflows.
WSL Versions¶
- WSL 2 (Recommended): Full Linux kernel, better performance, Docker support
- WSL 1: Compatibility layer, lower resource usage
We recommend WSL 2 for modern development.
Installation¶
Prerequisites¶
- Windows 10 version 2004+ or Windows 11
- Administrator access
Install WSL 2¶
Open PowerShell as Administrator and run:
1 | |
This installs: - WSL 2 - Linux kernel - Default distribution (Ubuntu)
Restart your computer after installation.
Verify Installation¶
1 | |
Should show WSL 2 with Linux kernel version.
Linux Distribution Setup¶
Choose Your Distribution¶
After WSL 2 installation, you have Ubuntu by default. You can also install other distributions:
1 2 3 4 5 | |
Launch WSL Terminal¶
From Windows:
1 2 3 4 5 | |
Or use Windows Terminal (recommended) for better UX.
Essential WSL Configuration¶
Optimize Performance¶
Create or edit ~/.wslconfig on Windows (in your Windows user directory):
1 2 3 4 5 6 7 8 9 10 11 12 | |
Adjust memory and processors based on your system.
Enable systemd¶
WSL 2 now supports systemd (system daemon). Add to ~/.wslconfig:
1 2 | |
Then restart WSL:
1 2 | |
This enables services like SSH, Docker, and other daemons.
Development Environment in WSL¶
Update Package Manager¶
1 2 | |
Install Essential Tools¶
1 2 3 4 5 6 7 8 9 10 11 | |
Install Development Runtimes¶
Install languages and runtimes you use:
1 2 3 4 5 6 7 8 9 | |
File System Integration¶
Access Windows Files from WSL¶
Windows drives are mounted at /mnt/c, /mnt/d, etc.:
1 2 3 4 5 | |
Access WSL Files from Windows¶
WSL files are accessible via \\wsl$\ in Windows Explorer:
1 | |
Or in PowerShell:
1 | |
SSH and Git in WSL¶
Configure SSH¶
WSL integrates with your host SSH setup. Your WSL SSH commands can use your Windows SSH keys or generate WSL-specific ones.
Generate a new key in WSL:
1 | |
Git Configuration¶
Set up Git in WSL (see Git section for detailed setup):
1 2 3 | |
Common WSL Commands¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Performance Tips¶
Use Native Storage¶
- Store projects in WSL filesystem (faster):
~/projects - Avoid Windows filesystem when possible:
/mnt/c/... - Cross-filesystem operations are slower
Mount Options¶
WSL 2 automatically optimizes mounts, but you can configure specific options in /etc/wsl.conf:
1 2 3 4 5 6 7 | |
Docker Desktop Integration¶
Install Docker Desktop for Windows with WSL 2 backend for best performance.
Troubleshooting¶
WSL Hangs or Freezes¶
1 2 3 4 5 | |
Out of Memory¶
Increase allocated memory in ~/.wslconfig:
1 2 | |
Networking Issues¶
If localhost doesn't work, ensure in ~/.wslconfig:
1 2 | |
Integration with Development Tools¶
Visual Studio Code¶
Install WSL Extension for seamless development.
1 2 3 4 5 | |
Terminal Emulators¶
Windows Terminal (Recommended): - Integrates WSL naturally - Multiple tabs and panes - Customizable profiles
Other Options: - Hyper - Alacritty - Kitty
Best Practices¶
- ✅ Use WSL 2 for better performance
- ✅ Install dev tools in WSL, not Windows
- ✅ Store projects in WSL filesystem
- ✅ Use Windows Terminal for better UX
- ✅ Enable systemd for daemon support
- ✅ Regularly update WSL and distributions
- ❌ Don't mix Windows and WSL paths in the same project
- ❌ Don't edit WSL files from Windows (permission issues)