The Windows Subsystem for Linux 2 (WSL2) is probably the simplest and most efficient solution to use Linux ap­pli­ca­tions in Windows. WSL2 allows access to Linux tools and ap­pli­ca­tions directly from the well-known Windows en­vi­ron­ment which makes it a good option for de­vel­op­ers. Due to its com­plete­ly revised ar­chi­tec­ture compared to WSL1, WSL2 is more per­for­mant than other options for using Linux tools in Windows.

What is WSL2?

WSL2, which was released in early 2020, is the further de­vel­op­ment of the Windows Subsystem for Linux (WSL1). Linux is an open source operating system and is, therefore, different to Windows, which is developed and dis­trib­uted as a com­mer­cial product. Linux can be a great option due to the wide range of developer tools and other software packages available free of charge.

What are the dif­fer­ences between WSL2 and its pre­de­ces­sor?

The fun­da­men­tal dif­fer­ence between WSL2 and its pre­de­ces­sor lies in the ar­chi­tec­ture of the software. While WSL1 provided a com­pat­i­bil­i­ty layer for trans­lat­ing code execution between Windows and Linux, WSL2 relies on the vir­tu­al­iza­tion of a Linux operating system. The virtual machine used for this runs on the native Windows hy­per­vi­sor, hyper-V.

While the func­tion­al­i­ty of the Linux interface provided by WSL1 was limited, WSL2 uses a complete Linux kernel. This is a kernel specially optimized for WSL2 both in terms of size and per­for­mance and is based on the stable original code from “kernel.org”. In use, this is reflected in the faster code execution by a factor of about two to twenty. Fur­ther­more, WSL2 requires less memory than the previous version. That the kernel is main­tained as part of the regular Windows updates makes it more con­ve­nient for its users, too.

Since WSL1 uses a trans­la­tion layer to mediate between Linux and Windows, some spe­cial­ized Linux software is left out in this version of WSL. In contrast, WSL2’s kernel vir­tu­al­iza­tion performs full system call com­pat­i­bil­i­ty. In practice, this means that even complex software like Docker can be operated within WSL2. Fur­ther­more, the GPU can be accessed from the Linux en­vi­ron­ment, which is par­tic­u­lar­ly useful for ap­pli­ca­tions with large datasets such as machine learning and data science.

What are the re­quire­ments for using WSL2?

The system re­quire­ments for using WSL2 depend on the processor installed in your machine:

  • For x64 systems, you need at least version 1903 with build 18362 or later.
  • For ARM64 systems, you need at least version 2004 with build 19041 or later.

If you are not sure which Windows edition and version you are running, you can check this with the following steps:

  • Press the Windows logo key + [R], type “winver” in the text box that appears and press [Enter].
  • Al­ter­na­tive­ly, click Start > Settings > System > Info > Windows Spec­i­fi­ca­tion and read the values there.

How can I use WSL2 on my own system?

In principle, there are two methods for using WSL2 on your system. We will show the two different methods in detail, depending on your situation:

  1. If you have not yet installed a Windows subsystem for Linux, install both the WSL2 on your system and set up a Linux dis­tri­b­u­tion.
  2. If you are already using WSL1, install WSL2 and upgrade the existing Linux dis­tri­b­u­tions.

To set up the WSL2 on your system, you need the Windows Pow­er­Shell. Note that you must start Pow­er­Shell as an ad­min­is­tra­tor to perform the in­stal­la­tion. Copy the commands shown to the Pow­er­Shell prompt and run them there.

WSL2 ac­ti­va­tion and in­stalling a Linux dis­tri­b­u­tion

If you do not have WSL1 installed on your system, follow our in­struc­tions to install both a WSL2 and a Linux dis­tri­b­u­tion:

Step 1: Activate the Windows-Subsystem for Linux

Copy and run the following command from the Pow­er­Shell prompt:

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

Step 2: Enable virtual computer functions

Copy and run the following command from the Pow­er­Shell prompt:

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

Step 3: Install update package for the Linux Kernel

First, download the ap­pro­pri­ate in­stal­la­tion package for your system. Then run the installer. Choose the ap­pro­pri­ate package depending on your computer processor:

Step 4: Set WSL2 as standard

Copy and run the following command from the Pow­er­Shell prompt:

wsl --set-default-version 2

Step 5: Restart

Restart your computer.

Step 6: Choose the Linux-Dis­tri­b­u­tion and install

Open the Microsoft Store and search for “Linux”. You will see a selection of available Linux dis­tri­b­u­tions.

Click on the Linux dis­tri­b­u­tion and then on “Install”. If you are not sure which dis­tri­b­u­tion is right for you, we recommend in­stalling Ubuntu Linux 20.04 LTS.

After the in­stal­la­tion is complete, click “Start”.

Step 7: Set up Linux-Dis­tri­b­u­tion

In the next window, the packages will be down­loaded and unpacked. This may take a few minutes. Finally, you will be prompted to specify a username and a password for the new Linux in­stal­la­tion.

Note

You can run several Linux dis­tri­b­u­tions in parallel with WSL. To do this, create a separate user account for each dis­tri­b­u­tion.

Upgrading an existing Linux dis­tri­b­u­tion from WSL1 to WSL2

Provided you are already using WSL1 and have set up a Linux in­stal­la­tion, go through steps 2-4 from the in­struc­tions above first. Then use the following Pow­er­Shell command to switch your installed Linux dis­tri­b­u­tion to WSL2:

wsl --set-version <distribution> 2</distribution>

The <dis­tri­b­u­tion> place­hold­er must be replaced with the name of an installed Linux dis­tri­b­u­tion. Use the following Pow­er­Shell command to display a list of installed Linux dis­tri­b­u­tions and view their names:

wsl --list --verbose
Note

The settings for an installed Linux dis­tri­b­u­tion are stored in a con­fig­u­ra­tion file “wsl.conf”. This file will keep working after switching to WSL2.

Con­clud­ing feature com­par­i­son between WSL2 and WSL1

As you have seen, using WSL2 offers many ad­van­tages over the previous version. To conclude this in­tro­duc­tion to WSL2, we have sum­ma­rized the sim­i­lar­i­ties and dif­fer­ences of the two versions for you:

Feature WSL1 WSL2
Provides in­te­gra­tion between Windows and Linux
Fast start-up of the Linux en­vi­ron­ment
High per­for­mance and low resource re­quire­ments
Based on virtual machine (VM)
Includes full Linux kernel
Provides full system call com­pat­i­bil­i­ty
Allows parallel use of VMware and Vir­tu­al­Box
Allows use across operating system file systems
Go to Main Menu