What is WSL1 and WSL2 ?? How to enable WSL2 on Windows 10

Ravindu Senal Fernando
4 min readJul 26, 2020

WSL stands for Windows Subsystem for Linux which was released first in 2016. It enables developers to run their favorite Linux environment natively on windows 10 without running a virtual machine or dual booting which is very resource consuming.

WSL1 enables Linux binaries to run on Windows using a compatibility layer which translates the Linux system calls into windows system calls. But WSL1 have some limitations like no support for GUI apps, not all commands can be run on WSL1 and cannot develop drivers.

Architecture of WSL

Due to the limitations in WSL1 Microsoft re-invented the the WSL1 and introduced WSL2 which is available in windows 10 version 2004 update. Instead of using a compatibility layer which converts Linux system calls to windows system calls, WSL2 offers its own isolated Linux kernel running on a thin version of the Hyper-V hypervisor (It enables to create virtual machines on x86–64 systems running windows) . The WSL2 hypervisor lets windows and Linux share the same timers without dominating the other. That allows Linux files to be hosted in a virtual disk.

Architecture of WSL2

Comparing WSL1 AND WSL2

In order to optimize for the fastest performance speed, be sure to store your project files in the Linux file system (not the Windows file system).

For example, when storing your WSL project files:

  • Use the Linux file system root directory: \\wsl$\Ubuntu-18.04\home\<user name>\Project
  • Not the Windows file system root directory: C:\Users\<user name>\Project

WSL 2 offers faster performance and 100% system call compatibility. However, there are a few specific scenarios where you might prefer using WSL 1. Consider using WSL 1 if:

  • Your project files must be stored in the Windows file system.
  • If you will be using your WSL Linux distribution to access project files on the Windows file system, and these files cannot be stored on the Linux file system, you will achieve faster performance across the OS files systems by using WSL 1.
  • A project which requires cross-compilation using both Windows and Linux tools on the same files.
  • File performance across the Windows and Linux operating systems is faster in WSL 1 than WSL 2, so if you are using Windows applications to access Linux files, you will currently achieve faster performance with WSL 1.

Installing WSL and update to WSL 2

Before installing any Linux distributions on Windows, you must enable the “Windows Subsystem for Linux” optional feature.

Open Power Shell as Administrator and run:

Power Shell

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

To only install WSL 1, you should now restart your machine and move on to install your Linux distribution of choice. You can download it from windows store.

To update to WSL 2, you must have running Windows 10, updated to version 2004, Build 19041 or higher.

Before installing WSL 2, you must enable the “Virtual Machine Platform” optional feature.

Open Power Shell as Administrator and run:

Power Shell

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your machine to complete the WSL install and update to WSL 2.

To activate WSL 2 you need to update the kernel component you can do it by visiting https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel and install the update by following the steps.

You can check the WSL version assigned to each of the Linux distributions you have installed by opening the Power Shell command line and entering the command (only available in Windows Build 19041 or higher): wsl -l -v

Power Shell

wsl --list --verbose

To set a distribution to be backed by either version of WSL please run:

Power Shell

wsl --set-version <distribution name> <versionNumber>

Make sure to replace <distribution name> with the actual name of your distribution and <versionNumber> with the number '1' or '2'. You can change back to WSL 1 at anytime by running the same command as above but replacing the '2' with a '1'.

If you want to make WSL 2 your default architecture you can do so with this command:

Power Shell

wsl --set-default-version 2

I hope you guys learnt something new by reading this article.

--

--