TExcelTAD
Home › Terminal & Command Line › WSL: Linux on Windows

WSL: Linux on Windows

The Windows Subsystem for Linux (WSL) runs real Linux distributions (Ubuntu, Debian, Fedora, openSUSE, Kali and more) directly on Windows, without dual-booting or managing a virtual machine yourself. You get a genuine bash, apt, grep, ssh and every Linux tool, side by side with your Windows apps. For developers it means the Linux commands from tutorials, Dockerfiles and CI scripts work on a Windows laptop exactly as written.

WSL 1 vs WSL 2

WSL 1 WSL 2 (default)
How it works translates Linux system calls into Windows ones runs a real Linux kernel in a lightweight Hyper-V VM
Compatibility most tools; no Docker, some syscalls missing full: Docker, systemd, FUSE, everything
Speed on Linux files good very fast
Speed on Windows files (/mnt/c) fast slower (files cross the VM boundary)
text
+------------------- Windows 11 ----------------------+
|  Windows apps   Windows Terminal   VS Code           |
|        |               |              |              |
|   C:\  (NTFS)     wsl.exe ------> +---------------+  |
|      ^                            | Linux kernel  |  |  WSL 2 utility VM
|      |  /mnt/c                    | Ubuntu (ext4) |  |
|      +----------------------------|  bash, apt... |  |
|        \\wsl.localhost\Ubuntu --->+---------------+  |
+------------------------------------------------------+

The internals (Hyper-V, the shared kernel, the 9P file protocol) are covered in WSL & Hyper-V.

Installing

On Windows 10 (2004+) and Windows 11, one command in an admin terminal installs WSL 2 and Ubuntu:

powershell
PS C:\Users\ada> wsl --install
Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Installing: Ubuntu
Ubuntu has been installed.
The requested operation is successful. Changes will not be effective until the system is rebooted.

(sample output — the wording varies by version). After the reboot, Ubuntu opens and asks for a Linux user name and password. They are independent of your Windows account; the password is what sudo asks for later.

To pick another distribution, list what's available and install it by name:

powershell
PS C:\Users\ada> wsl --list --online
NAME                            FRIENDLY NAME
Ubuntu                          Ubuntu
Debian                          Debian GNU/Linux
FedoraLinux-42                  Fedora Linux 42
Ubuntu-24.04                    Ubuntu 24.04 LTS
...
PS C:\Users\ada> wsl --install -d Debian

wsl.exe: the control command

wsl.exe works from CMD and PowerShell alike. The everyday commands:

Command Does
wsl open the default distribution in the current folder
wsl -d Debian open a specific distribution
wsl -l -v list installed distributions, their state and WSL version
wsl --set-default Debian change the default distribution
wsl --shutdown stop all distributions and the VM (fixes most "stuck" problems)
wsl -t Ubuntu terminate one distribution
wsl --update update the WSL kernel and components
wsl --status default distribution and version
wsl --export Ubuntu ubuntu.tar / --import back up or clone a distribution
wsl --unregister Ubuntu delete a distribution and all its files
wsl ls -la / wsl -e cmd args run a single Linux command from Windows
cmd
C:\Users\ada> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         2
  Debian    Stopped         2

(sample output). The * marks the default distribution. Each distribution also appears automatically as a profile in Windows Terminal.

Files: two worlds, two directions

Windows drives are mounted inside Linux under /mnt/<drive letter>, and Linux files are visible to Windows through a network-style path:

From To reach Use
Linux your Windows user folder /mnt/c/Users/ada
Windows your Linux home \\wsl.localhost\Ubuntu\home\ada (older: \\wsl$\Ubuntu\home\ada)
Linux open the current folder in Explorer explorer.exe .
Linux convert a path wslpath 'C:\Users\ada' → /mnt/c/Users/ada, wslpath -w ~ → \\wsl.localhost\Ubuntu\home\ada

The conversion rule is mechanical: drive letter lower-cased under /mnt, backslashes become slashes. Here is the idea as a small bash function (on a real WSL system, use wslpath):

bash · try it yourself
to_wsl() {
  local p="${1//\\//}"                         # backslashes -> slashes
  local drive="${p:0:1}"
  printf '/mnt/%s%s\n' "${drive,,}" "${p:2}"   # C: -> /mnt/c
}
to_wsl 'C:\Users\ada\Documents\report.docx'
to_wsl 'D:\projects\site'
cd_target=$(to_wsl 'C:\Program Files\Git')
echo "Quote it, it has a space: cd \"$cd_target\""
/mnt/c/Users/ada/Documents/report.docx
/mnt/d/projects/site
Quote it, it has a space: cd "/mnt/c/Program Files/Git"

And the other direction, from a Linux path to the UNC path Windows Explorer understands, in PowerShell:

powershell · try it yourself
function ConvertTo-WslUnc([string]$LinuxPath, [string]$Distro = "Ubuntu") {
    "\\wsl.localhost\$Distro" + ($LinuxPath -replace '/', '\')
}
ConvertTo-WslUnc /home/ada/projects
ConvertTo-WslUnc /etc/wsl.conf -Distro Debian
\\wsl.localhost\Ubuntu\home\ada\projects
\\wsl.localhost\Debian\etc\wsl.conf

Tip: Keep projects you work on with Linux tools inside the Linux file system (~/projects), not under /mnt/c. On WSL 2, git status or npm install on Linux files is many times faster, and file watchers work reliably. VS Code's WSL extension (code . from the WSL shell) edits those files from Windows seamlessly.

Mixing Windows and Linux commands

WSL's interop lets each side call the other:

bash
ada@laptop:~/projects$ notepad.exe notes.txt          # a Windows program from bash
ada@laptop:~/projects$ ipconfig.exe | grep IPv4       # Windows output, Linux filter
   IPv4 Address. . . . . . . . . . . : 192.168.1.42
ada@laptop:~/projects$ cat todo.txt | clip.exe        # copy to the Windows clipboard
powershell
PS C:\Users\ada> wsl grep -c TODO notes.txt            # a Linux program from PowerShell
3
PS C:\Users\ada> Get-Content big.log | wsl sort | wsl uniq -c

Windows programs need the .exe suffix when called from Linux. Your Windows PATH is appended to the Linux PATH, so code, explorer.exe and git.exe are found automatically.

Configuration

  • /etc/wsl.conf inside a distribution: per-distribution settings, e.g. turn on systemd (default in new Ubuntu installs) or set the default user.
  • %UserProfile%\.wslconfig on Windows: settings for the WSL 2 VM, e.g. memory and CPU limits.
ini
# /etc/wsl.conf
[boot]
systemd=true

[user]
default=ada
ini
# C:\Users\ada\.wslconfig
[wsl2]
memory=8GB
processors=4

Run wsl --shutdown after editing either file so the changes take effect.

When to use WSL

Use WSL for Prefer native Windows for
Linux-first tools: bash scripts, make, gcc, Ruby/Python stacks that expect Linux Windows administration (services, registry, Active Directory): PowerShell
Docker Desktop's backend, Kubernetes tooling .NET desktop apps, Visual Studio projects
Matching the Linux servers you deploy to Batch files and installers for Windows users
Following Linux/macOS tutorials as written Games and GPU-heavy Windows apps

Learn more: WSL & Hyper-V, The Terminal on Linux, Linux & Bash course.

Test yourself

Where are your Windows C: drive files inside a WSL distribution?

  1. /c
  2. /mnt/c
  3. /windows/c
  4. \\wsl$\c

Which command stops every running WSL distribution and the WSL 2 VM?

  1. wsl --stop
  2. wsl -l -v
  3. wsl --shutdown
  4. wsl --unregister

Why should a Node.js project you build with Linux tools live in ~/projects instead of /mnt/c/projects on WSL 2?

  1. Windows can't see ~/projects
  2. Linux file system access is much faster and file watching is reliable
  3. npm refuses to run on /mnt/c
  4. Files under /mnt/c are read-only