wsl
Manage and interact with Windows Subsystem for Linux
SYNOPSIS
wsl [options]
wsl command [options]
wsl -d DistributionName [LinuxCommand [args...]]
PARAMETERS
--install [Distribution]
Installs the Windows Subsystem for Linux and optionally a specified Linux distribution. If no distribution is specified, it defaults to Ubuntu.
-l, --list [options]
Lists all installed Linux distributions. Use options like --running to list only running distributions or --all to list all, including stopped ones. --verbose provides more details.
-d, --distribution DistributionName
Runs a specified Linux distribution. If a command is provided after the distribution name, it will execute that command within the distribution; otherwise, it will launch the default shell.
-u, --user Username
Runs a command or opens the shell as the specified user within the current or specified distribution.
--shutdown
Immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine.
--terminate DistributionName
Terminates a specific running distribution instance.
--unregister DistributionName
Unregisters and uninstalls a specified distribution, deleting all data associated with it.
--export DistributionName FileName
Exports the specified distribution to a tar file. The tar file can then be imported to another machine.
--import DistributionName InstallLocation FileName
Imports the specified tar file as a new distribution. InstallLocation is the directory where the distribution will be stored.
--set-default DistributionName
Sets the specified distribution as the default for wsl commands.
--set-version DistributionName VersionNumber
Converts the specified distribution to the target WSL version (1 or 2).
--update
Updates the WSL 2 Linux kernel to the latest version.
--status
Displays the status of the WSL installation, including its version and whether it's running.
--mount DiskPath
Attaches and mounts a physical disk or virtual hard disk (VHD) into all running WSL 2 distributions, allowing access to its file systems.
--unmount [DiskPath]
Unmounts a specified disk or all mounted disks if no path is provided.
--version
Displays information about the WSL version.
-h, --help
Displays help information for the wsl command.
DESCRIPTION
The wsl command is a command-line utility for Windows that enables users to interact with and manage the Windows Subsystem for Linux (WSL).
WSL provides a compatibility layer for running Linux binary executables natively on Windows. The wsl command serves as the primary interface for a wide range of tasks, including installing new Linux distributions, launching existing ones, managing their operational state (running, stopped), and performing advanced operations such as exporting, importing, and unregistering distributions. It bridges the gap between Windows and Linux environments, allowing developers and users to leverage the power of both operating systems simultaneously without the overhead of traditional virtual machines or dual-booting. It supports various popular Linux distributions like Ubuntu, Debian, Fedora, and more, which are typically available through the Microsoft Store.
CAVEATS
The wsl command is a Windows utility, not a native Linux command, used for managing Linux environments hosted on Windows.
It requires Windows 10 or Windows 11 with the WSL feature enabled.
While WSL provides excellent compatibility, some Linux applications requiring direct hardware access, specific kernel modules, or very high I/O performance might not function optimally compared to a native Linux installation or traditional virtual machines.
WSL 1 VS WSL 2
WSL 1 used a compatibility layer to translate Linux system calls into Windows NT kernel calls. It offered good integration but had limitations in performance and full system call compatibility.
WSL 2 utilizes a lightweight virtual machine (VM) that runs a genuine Linux kernel. This change provides significantly better performance for I/O intensive operations, full system call compatibility, and supports more advanced features like Docker Desktop integration. WSL 2 is generally recommended for most users.
ACCESSING WINDOWS FILES
From within a WSL distribution, Windows drives are automatically mounted under the /mnt/ directory. For example, your Windows C: drive is accessible at /mnt/c/. Similarly, from Windows, you can access your Linux files using the network path \\wsl$ followed by the distribution name (e.g., \\wsl$\Ubuntu).
NETWORKING
In WSL 2, distributions run within a lightweight VM that uses a virtual network adapter. By default, WSL 2 uses Network Address Translation (NAT) and an internal IP address. This typically means you can access Windows network resources from within WSL, and Windows applications can access services running on WSL via localhost for port-forwarded services, or by using the WSL 2 VM's IP address. For more advanced scenarios, specific networking configurations might be required.
HISTORY
The Windows Subsystem for Linux (WSL) was first introduced in the Windows 10 Anniversary Update in 2016 (later retroactively named WSL 1). This initial version provided a translation layer that allowed Linux binary executables to run directly on Windows.
A significant advancement came with WSL 2, released in Windows 10, version 2004 (2020). WSL 2 redesigned the architecture to use a lightweight virtual machine with a real Linux kernel, dramatically improving file system performance, full system call compatibility, and enabling new features like Docker Desktop integration. Subsequent updates have continuously added features such as GPU compute support, the ability to run Linux GUI applications, and simplified installation via wsl --install.