Quick Answer: Install WSL:
wsl --install(PowerShell as admin). This installs WSL2 + Ubuntu. Open Ubuntu from Start menu. Update:sudo apt update && sudo apt upgrade. Access Windows files:/mnt/c/. Access Linux files from Windows:\\wsl$\Ubuntu\.
Install WSL
Quick Install (Windows 10 2004+ / Windows 11)
Open PowerShell as Administrator:
wsl --install
This installs WSL2 + Ubuntu by default. Restart when prompted.
Install a Specific Distro
# List available distros
wsl --list --online
# Install a specific one
wsl --install -d Debian
wsl --install -d Ubuntu-24.04
wsl --install -d kali-linux
wsl --install -d openSUSE-Leap-15.6
Set WSL Version
# Check current WSL version
wsl --list --verbose
# Set default version to WSL2
wsl --set-default-version 2
# Convert a distro from WSL1 to WSL2
wsl --set-version Ubuntu 2
| WSL1 | WSL2 | |
|---|---|---|
| Architecture | Translation layer | Real Linux kernel in VM |
| Filesystem | Slow Linux FS, fast Windows FS | Fast Linux FS, slower Windows FS |
| Syscall support | Partial | Full |
| Docker | No | Yes |
| GPU/CUDA | No | Yes |
| Networking | Shared with Windows | Virtual network (NAT) |
| Recommended | Legacy only | Yes (default) |
Manage Distros
# List installed distros
wsl --list --verbose
# or
wsl -l -v
# Set default distro
wsl --set-default Ubuntu
# Run a specific distro
wsl -d Debian
# Run as root
wsl -u root
# Shut down all WSL instances
wsl --shutdown
# Shut down a specific distro
wsl --terminate Ubuntu
# Unregister (delete) a distro
wsl --unregister Ubuntu
# Export a distro to backup
wsl --export Ubuntu ubuntu-backup.tar
# Import a distro from backup
wsl --import MyUbuntu C:\WSL\MyUbuntu ubuntu-backup.tar
# Check WSL status
wsl --status
# Update WSL
wsl --update
File System Access
From Linux → Windows Files
# Windows drives are mounted at /mnt/
ls /mnt/c/Users/Sam/Desktop/
# Edit a Windows file
nano /mnt/c/Users/Sam/Documents/file.txt
# Copy file from Windows to Linux
cp /mnt/c/Users/Sam/file.txt ~/
# Performance tip: working on /mnt/ is SLOW
# Copy files to Linux filesystem for fast operations
cp -r /mnt/c/project ~/project
From Windows → Linux Files
# In File Explorer address bar:
\\wsl$\Ubuntu\home\sam\
# Or from PowerShell:
explorer.exe \\wsl$\Ubuntu\home\sam\
From Linux → Open Windows Explorer
# Open current directory in Explorer
explorer.exe .
# Open a specific folder
explorer.exe /mnt/c/Users/
Networking
Access Linux Services from Windows
# Start a web server in WSL
python3 -m http.server 8080
# Access from Windows browser:
# http://localhost:8080
WSL2 automatically forwards localhost ports to Windows.
Access Windows from WSL
# Get Windows host IP
cat /etc/resolv.conf | grep nameserver
# Usually: 172.x.x.1
# Or use the hostname
ping "$(hostname).local"
Port Forwarding (Access WSL from LAN)
By default, WSL services are only accessible from the Windows host. To expose to your LAN:
# PowerShell as admin
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=localhost
# Remove the forward
netsh interface portproxy delete v4tov4 listenport=8080 listenaddress=0.0.0.0
# List all forwards
netsh interface portproxy show all
Docker in WSL
Option 1: Docker Desktop (Easier)
- Install Docker Desktop for Windows
- In Settings → Resources → WSL Integration → Enable for your distro
- Docker commands work directly in WSL:
docker run hello-world
docker compose up -d
Option 2: Docker Engine in WSL (No Docker Desktop)
# Install Docker directly in WSL
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# Start Docker (if systemd is enabled)
sudo systemctl start docker
# Or start manually
sudo dockerd &
Systemd
WSL2 supports systemd (since September 2022):
# Check if systemd is enabled
ps -p 1 -o comm=
# Should show: systemd (not: init)
# Enable systemd
sudo nano /etc/wsl.conf
Add:
[boot]
systemd=true
Then restart WSL:
wsl --shutdown
wsl
Now you can use systemctl:
sudo systemctl start nginx
sudo systemctl enable docker
systemctl status ssh
VS Code Integration
# Open current directory in VS Code (from WSL terminal)
code .
# Open a specific file
code myfile.py
# Install VS Code extension: "WSL" (by Microsoft)
# This lets VS Code run in Windows but execute code in WSL
VS Code automatically detects WSL and offers to "Reopen in WSL" for Linux projects.
GPU and CUDA
WSL2 supports GPU passthrough for machine learning:
# Check if GPU is available (drivers come from Windows — never install them in WSL)
nvidia-smi
# Install CUDA toolkit (use NVIDIA's WSL repo, NOT apt nvidia-cuda-toolkit)
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt install cuda-toolkit -y
# Test with Python
pip install torch
python3 -c "import torch; print(torch.cuda.is_available())"
Requirement: NVIDIA GPU + latest Windows GPU drivers. WSL handles the rest. Never install NVIDIA drivers inside WSL — they come from Windows automatically.
WSL Configuration
Per-Distro Config: /etc/wsl.conf
[boot]
systemd=true
# command = /opt/startup.sh # Run on WSL start
[automount]
enabled=true
root=/mnt/
options="metadata,umask=22,fmask=11"
[network]
generateHosts=true
generateResolvConf=true
# hostname = myhost
[interop]
enabled=true # Run Windows executables from Linux
appendWindowsPath=true # Add Windows PATH to Linux PATH
[user]
default=sam # Default login user
After editing, restart: wsl --shutdown
Global Config: %USERPROFILE%\.wslconfig
[wsl2]
memory=8GB # Limit memory (default: 50% of host)
processors=4 # Limit CPUs
swap=4GB # Swap size
localhostForwarding=true
[experimental]
autoMemoryReclaim=gradual # Return unused memory to Windows
sparseVhd=true # Auto-shrink disk image
Useful Commands
Run Linux Commands from PowerShell
# Run a single command
wsl ls -la
# Run as specific user
wsl -u root apt update
# Pipe between Windows and Linux
dir | wsl grep ".txt"
wsl ls /home | findstr sam
Run Windows Commands from WSL
# Run any Windows executable
notepad.exe file.txt
explorer.exe .
cmd.exe /c dir
powershell.exe -Command "Get-Process"
clip.exe < file.txt # Copy to Windows clipboard
Troubleshooting
# Reset WSL networking
wsl --shutdown
netsh winsock reset
# Restart computer
# Check WSL version and kernel
wsl --status
# Update WSL kernel
wsl --update
# Repair WSL
wsl --install --no-distribution
| Problem | Fix |
|---|---|
wsl --install does nothing |
Enable "Virtual Machine Platform" in Windows Features |
| WSL2 very slow | Working on /mnt/c/ is slow. Copy files to Linux FS (~/) |
| Can't access localhost from Windows | wsl --shutdown and restart |
| DNS not resolving | Edit /etc/wsl.conf: set generateResolvConf=false, manually set DNS in /etc/resolv.conf |
| Out of disk space | Compact the VHD: wsl --shutdown then Optimize-VHD in PowerShell |
| "WSL2 requires kernel update" | Run wsl --update |
| Permission errors on /mnt/c | Add options="metadata" to [automount] in /etc/wsl.conf |
| Docker won't start | Enable systemd first. Or use Docker Desktop |
| Slow internet in WSL | Try: wsl --shutdown, or disable Windows Firewall temporarily to test |
Quick Reference
| Command | What It Does |
|---|---|
wsl --install |
Install WSL + Ubuntu |
wsl --install -d Debian |
Install specific distro |
wsl --list --verbose |
List distros with WSL version |
wsl --shutdown |
Shut down all WSL |
wsl --terminate Ubuntu |
Shut down one distro |
wsl --set-default Ubuntu |
Set default distro |
wsl --export Ubuntu file.tar |
Backup distro |
wsl --import Name Path file.tar |
Restore distro |
wsl --update |
Update WSL |
wsl -u root |
Enter as root |
explorer.exe . |
Open current dir in Explorer |
code . |
Open in VS Code |
Related Guides
- Linux Commands Cheat Sheet — essential Linux commands
- Bash Cheat Sheet — shell scripting
- Docker Cheat Sheet — Docker in WSL
- SSH Cheat Sheet — remote access
- Git Cheat Sheet — version control
- How to Enable SSH — SSH server in WSL
- apt Cheat Sheet — package management