Master WSL 2: A Concise Guide for Windows Subsystem for Linux

Windows Subsystem for Linux (WSL 2)
Windows Subsystem for Linux (WSL 2)

This article provides a concise guide for Windows Subsystem for Linux (WSL 2), which includes installation, basic operations, configuration tips, and troubleshooting.

Installation

You can refer the article to have WLS 2 installed.

Learn To Install Windows Subsystem For Linux (WSL) 2 On Windows In Two Ways: Online And Offline – Temple Spark

Basic Operations

Open WSL Terminal

Launch your installed Linux distribution via the Start menu or run wsl in PowerShell/CMD.

List Installed Distributions

Check your installed distributions:

C:\>wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 2
Fedora Running 2

Set Default Distribution

If you have multiple distributions, set a default one with:

# wsl --set-default <DistributionName>
C:\>wsl --set-default Fedora

Launch a Specific Distribution: Launch a distribution directly:

# wsl -d <DistributionName>
C:\>wsl -d Ubuntu
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.146.1-microsoft-standard-WSL2 x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.

https://ubuntu.com/engage/secure-kubernetes-at-the-edge

This message is shown once a day. To disable it please create the
/home/dynotes/.hushlogin file.
ubuntu@WIN-Flutter:/mnt/c$

File System Access

  • Access Windows Files from Linux: Navigate to /mnt/c to access your C: drive, replace c with the appropriate letter for other drives.
  • Access Linux Files from Windows: Use the \\wsl$\<DistributionName> path in File Explorer.

Configuration and Usage

Change the WSL Version for a Distribution

To switch between WSL 1 and WSL 2 for a specific distribution:

C:\>wsl --set-version <DistributionName> 2

View WSL Configuration

View your current WSL configuration with:

C:\>wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 2
Fedora Running 2

Networking

Access Linux Services from Windows: Use localhost or the IP address displayed by hostname -I in your Linux terminal.

Updating, Upgrading & Troubleshooting

Update Your Linux Distribution

Regularly update your distribution with:

$ ### Ubuntu
$ sudo apt update && sudo apt upgrade

Restart WSL

If you encounter issues, restart WSL with:

### Immediately terminates all running distributions and the WSL 2
C:\>wsl --shutdown

### Terminates the specified distribution
C:\>wsl -t Ubuntu
The operation completed successfully.

Check for Windows Updates

Ensure your Windows 10 or 11 version supports WSL 2.

You Might Also Like

Leave a Reply