Installing Windows Subsystem for Linux 2 (WSL2) on Windows 10

The Windows Substem for Linux allows you to run a GNU/Linux environment on your Windows 10 system. May 2019 Microsoft made WSL2 available, a vast improvement on WSL1 because they now provide a full Linux kernel. WSL2 has been GA since the 2004 update of Windows 10 in May 2020.

This blog post is the result of my troubles in upgrading from WSL1 to WSL2. You can also use these instructions to install from scratch.

Windows version

As stated before, WSL2 is GA as of the 2004 update of Windows 10. That does not mean you need that particular version of Windows 10. To run WSL2, the minimum build version required is 18917.
Checking your build version of Windows 10 can be done in many ways, this method uses PowerShell.

  1. Open Start
  2. Type PowerShell and right-click the top search result
  3. Select Run as administrator
  4. In the PowerShell console type the following
    [System.Environment]::OSVersion.Version

    Windows Build Version

If your build is lower then 18917, you must first update Windows before you can continue.

Enable the Windows Subsystem for Linux 1

This step is only required if you are starting from scratch. If you already have WSL1 installed, go to the next section.

  1. Open Start
  2. Type Turn Windows features on or off and open the top search result
  3. Click the checkbox for Windows Subsystem for Linux
    Turn Windows features on or off
  4. Click the OK button and restart

Enable the Virtual Machine Platform

One key difference in architecture between WSL1 and WSL2 is that WSL2 runs it’s kernel in a lightweight virtual machine. So to use WSL2, the Virtual Machine Platform on Windows 10 needs to be started.

  1. Open Start
  2. Type PowerShell and right-click the top search result
  3. Select Run as administrator
  4. In the PowerShell console type the following
    Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

    Enable virtual machine platform

  5. The official docs advise restarting your computer. I, however, did not do this.

Install Windows Subsystem for Linux 2 Kernel update

To use WSL2 a kernel update is required.

  1. Download the kernel from here or use this direct link.
  2. Run the downloaded file.

For me running the file did not work. Every time I launched the msi, I received the following error: This update only applies to machines with the Windows Subsystem for Linux.

WSL kernel update error

To solve this.

  1. Open Start
  2. Type PowerShell and right-click the top search result
  3. Select Run as administrator
  4. In PowerShell cd into the directory where you downloaded the msi
  5. Type the following
    msiexec -fav wsl_update_x64.msi

 

Enable the Windows Subsystem for Linux 2

With the prerequisites done, we are ready to set de default WSL to version2.

  1. Open Start
  2. Type PowerShell and right-click the top search result
  3. Select Run as administrator
  4. In the PowerShell console type the following
    wsl --set-default-version 2

    wsl set default version

 

Convert existing distributions

This step is only required if you created a distribution for WSL1 and you want to convert it to WSL2.

  1. Open Start
  2. Type PowerShell and right-click the top search result
  3. Select Run as administrator
  4. The first thing to do is to list all the existing distro’s. In the PowerShell console type the following
    wsl --list --verbose

    wsl1 listing

  5. Choose the distro you wish to convert into WSL2. In my case, there is only one, Ubuntu-18.04. Convert it into WSL2 using the following command
    wsl --set-version Ubuntu-18.04 2

    Update existing distro's

  6. Finally, verify that updating was successful by listing the wsl again.
    wsl2 listing

That’s it, and you are done. You have now enabled WSL2, set it as the default version to use when creating new distros and converted your existing WSL1 distros.

Tip: enable virtualization

Don’t forget to enable virtualization in your BIOS before you start!

Tip: PowerShell console

Many of the subsections started with opening a PowerShell console. If you do these steps in quick succession, you can, of course, use a single console. There is no need to run each step in a separate console.

Author

Emiel Kremers

Partner at FourCo Specialising in Cloud and Big Data infrastructure.