Mastering WSL

A Beginner-Friendly Guide to Using WSL on Windows

Table of Contents

Part 1: Introduction & Getting Started

What is WSL?

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.

Why Use WSL?

WSL Versions

Installing WSL (The Easy Way)

For Windows 10 (2004+) or Windows 11:

  1. Open PowerShell as Administrator
  2. Run the following command:
    wsl --install
  3. Restart your computer if prompted
  4. On reboot, a terminal window will launch asking you to set up your Linux username and password

This installs WSL and sets WSL 2 as the default version. It also installs Ubuntu as the default Linux distribution.

Installing a Specific Linux Distro

If you want a different distribution (like Debian, Kali Linux, etc.), run:

wsl --install -d <DistroName>

Example:

wsl --install -d Debian

Checking Installed Distros

wsl --list --online

This shows all available distros you can install.

Switching Between WSL Versions

By default, WSL uses version 2. To manually switch a distro's version:

wsl --set-version <DistroName> 2

Example:

wsl --set-version Ubuntu 2

Setting Default Version for New Installs

wsl --set-default-version 2

Using WSL for the First Time

To launch your installed Linux distro:

wsl

Or to launch a specific one:

wsl -d <DistroName>

Useful First Commands (Inside WSL Terminal)

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.

Accessing Windows Files from WSL

Your C: drive is mounted inside WSL at /mnt/c. You can access any file using:

cd /mnt/c/Users/<YourWindowsUsername>/

Accessing WSL Files from Windows

Open File Explorer and type:

\\wsl$

You'll see all installed Linux distributions and their file systems.

Part 2: Managing WSL Distros and System Configuration

Listing Installed Distros

To see all the Linux distributions you have installed:

wsl --list

or

wsl -l

Example Output:

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

Setting a Default Distro

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.

Uninstalling a Distro

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!

Exporting and Backing Up a 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.

Importing a Distro from Backup

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

Changing WSL Version (1 or 2)

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

Shutting Down and Terminating

This is useful if something hangs or you want to free up resources.

Checking System Configuration

Run this to see:

wsl --status

Updating the WSL Kernel

Microsoft occasionally updates the WSL 2 kernel. To update:

wsl --update

If something breaks and you want to roll back:

wsl --update rollback

Full Help Command

To see everything WSL can do, use:

wsl --help

This gives a list of all commands and options.

Part 3: Interoperability, File Access & Advanced WSL Configuration

1. Accessing Windows Files from Linux (WSL)

Inside your WSL terminal, Windows drives are mounted under /mnt/.

Examples:

Action Command
Navigate to C:\Users\YourName\Downloads cd /mnt/c/Users/YourName/Downloads
List contents of D: drive ls /mnt/d

2. Accessing WSL Files from Windows

To explore your WSL file system through Windows File Explorer:

  1. Press Win + R
  2. Type: \\wsl$
  3. Hit Enter

This opens a network-style view of all installed Linux distros. You can drag/drop files in and out from here.

3. Running Linux Commands from Windows (PowerShell or CMD)

You can execute Linux commands directly from a Windows terminal using:

wsl <linux-command>

Examples:

wsl ls -la
wsl cat /etc/os-release

To run a Linux command in a specific distro:

wsl -d <DistroName> <command>

4. Running Windows Programs from Linux (WSL)

Inside WSL, you can launch Windows apps using their .exe names.

Examples:

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

5. Advanced Configuration Files

WSL supports two config files for custom behavior:

A. Global Config: .wslconfig

Location: C:\Users\<YourWindowsUsername>\.wslconfig

This file affects all WSL 2 distributions.

Example .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

B. Per-Distro Config: wsl.conf

Location: Inside each distro at /etc/wsl.conf

Example 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.

6. Tips & Best Practices

7. Troubleshooting Common Issues

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)

Want More?

Conclusion

You've now mastered:

This guide is made to be saved, starred and shared. Happy coding!