WSL (Windows Subsystem for Linux) is a compatibility layer developed by Microsoft that allows you to run a GNU/Linux environment directly on Windows—without the need for a traditional virtual machine or dual-boot setup.
With WSL, you can execute Linux commands, use open-source tools, and even run Linux applications side-by-side with your Windows workflow.
bash, gcc, apt, git) natively on Windows.For Windows 10 (2004+) or Windows 11:
wsl --install
This installs WSL and sets WSL 2 as the default version. It also installs Ubuntu as the default Linux distribution.
If you want a different distribution (like Debian, Kali Linux, etc.), run:
wsl --install -d <DistroName>
Example:
wsl --install -d Debian
wsl --list --online
This shows all available distros you can install.
By default, WSL uses version 2. To manually switch a distro's version:
wsl --set-version <DistroName> 2
Example:
wsl --set-version Ubuntu 2
wsl --set-default-version 2
To launch your installed Linux distro:
wsl
Or to launch a specific one:
wsl -d <DistroName>
| Command | Description |
|---|---|
ls |
Lists files in the current directory. |
cd |
Changes directory. |
pwd |
Prints the current directory path. |
mkdir <dir> |
Creates a new directory. |
sudo apt update && sudo apt upgrade |
Updates your Linux packages. |
exit |
Exits the WSL terminal and returns to Windows. |
Your C: drive is mounted inside WSL at /mnt/c. You can access any file using:
cd /mnt/c/Users/<YourWindowsUsername>/
Open File Explorer and type:
\\wsl$
You'll see all installed Linux distributions and their file systems.
To see all the Linux distributions you have installed:
wsl --list
or
wsl -l
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
Debian
Kali-Linux
To see which ones are currently running:
wsl --list --running
To see versions (WSL 1 or 2) of each installed distro:
wsl -l -v
If you use one distro more than others, make it the default:
wsl --set-default <DistroName>
Example:
wsl --set-default Debian
Now, running just wsl will launch Debian.
To remove (unregister) a distro and delete all its data:
wsl --unregister <DistroName>
Example:
wsl --unregister Ubuntu
Warning: This permanently deletes the Linux file system for that distro!
To create a backup of your entire Linux distro:
wsl --export <DistroName> <PathToFile.tar>
Example:
wsl --export Ubuntu ubuntu-backup.tar
This file can be stored and later restored.
To import your saved distro to a new location:
wsl --import <NewDistroName> <InstallLocation> <BackupFile.tar>
Example:
wsl --import UbuntuBackup C:\WSL\Ubuntu\ ubuntu-backup.tar
You can choose which version each distro uses:
wsl --set-version <DistroName> <1|2>
Example:
wsl --set-version Kali-Linux 2
To set WSL 2 as the default for all new installs:
wsl --set-default-version 2
wsl --shutdown
wsl --terminate <DistroName>
This is useful if something hangs or you want to free up resources.
Run this to see:
wsl --status
Microsoft occasionally updates the WSL 2 kernel. To update:
wsl --update
If something breaks and you want to roll back:
wsl --update rollback
To see everything WSL can do, use:
wsl --help
This gives a list of all commands and options.
Inside your WSL terminal, Windows drives are mounted under /mnt/.
| Action | Command |
|---|---|
Navigate to C:\Users\YourName\Downloads |
cd /mnt/c/Users/YourName/Downloads |
| List contents of D: drive | ls /mnt/d |
To explore your WSL file system through Windows File Explorer:
Win + R\\wsl$This opens a network-style view of all installed Linux distros. You can drag/drop files in and out from here.
You can execute Linux commands directly from a Windows terminal using:
wsl <linux-command>
wsl ls -la
wsl cat /etc/os-release
To run a Linux command in a specific distro:
wsl -d <DistroName> <command>
Inside WSL, you can launch Windows apps using their .exe names.
notepad.exe
code.exe # Opens VS Code
explorer.exe . # Opens current directory in File Explorer
You can also use Windows paths in commands, just prefix them with /mnt/:
cat /mnt/c/Users/YourName/Desktop/note.txt
WSL supports two config files for custom behavior:
.wslconfigLocation: C:\Users\<YourWindowsUsername>\.wslconfig
This file affects all WSL 2 distributions.
.wslconfig:[wsl2]
memory=4GB
processors=2
swap=2GB
localhostForwarding=true
| Option | Description |
|---|---|
memory |
Max RAM WSL can use |
processors |
Number of CPU cores |
swap |
Swap file size |
localhostForwarding |
Enables Windows to Linux networking |
After editing this file, restart WSL:
wsl --shutdown
wsl.confLocation: Inside each distro at /etc/wsl.conf
wsl.conf:[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
[network]
generateResolvConf = false
This file controls:
Restart the WSL distro after editing this config.
--export.code .) for full-featured Linux dev on Windows.sudo apt update && sudo apt upgrade frequently to keep Linux packages updated./mnt/ instead).| Problem | Solution |
|---|---|
| WSL not launching | Restart computer or run wsl --shutdown |
| File permission errors | Check mount options in wsl.conf |
| Can't access Windows files | Try navigating to /mnt/c/Users/ |
| WSL commands not recognized | Make sure Windows features are enabled (see Part 1) |
Comprehensive documentation from Microsoft
Source code and latest updates
Community support and feedback
You've now mastered:
This guide is made to be saved, starred and shared. Happy coding!