DEV Community

loading...

Upgrading from WSL1 to WSL2

adityakanekar profile image Aditya Kanekar Updated on ・3 min read

Background

In my last post I talked about how to get started with developing applications on Linux on Windows 10 using WSL 2 and VS Code. Some of you might have installed the previous version of WSL1 on your Windows 10 machines. This article guides on how to upgrade from WSL to WSL2.

Install WSL2 Linux Kernel

You need at least 1903 version of Windows 10. You can check the minimum requirement for upgrading from WSL1 here To check windows version, click Windows + R Key and type,

winver
Enter fullscreen mode Exit fullscreen mode

You will be able to see the build version of your windows e.g. 1903.

Download the installer for the WSL2 kernel from,
https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel

Run the installer to install WSL2 Kernel for Linux. Once the installation is successful. Open PowerShell or command prompt and run,

wsl --list 
Enter fullscreen mode Exit fullscreen mode

This will list all the distros and the version of WSL in the version column. The list will look somewhat similar to this,

Alt Text

Since you were running WSL1 previously on your machine the distro is still using WSL1. No magic tricks here, none of your distros will be migrated to WSL2 by default.

Upgrading from WSL1 to WSL2

To upgrade your current distro(s) from WSL1 to WSL2. Run following command in PowerShell or command prompt,

wsl --set-version <distro-name> 2
Enter fullscreen mode Exit fullscreen mode

Replace the distro-name with the Name displayed in the last section. So in our case the command will look like,

wsl --set-version Ubuntu-20.04 2
Enter fullscreen mode Exit fullscreen mode

This will take some time to upgrade, in my experience all your data will be retained as it was previously. Once the upgrade is complete you can run the list distros command to verify whether the version was successfully upgraded.

wsl -l -v
Enter fullscreen mode Exit fullscreen mode

You should be able to see output similar to,

Alt Text

Now you can launch Ubuntu-20.04 from Start menu or from the command prompt run,

wsl -d Ubuntu-18.04
Enter fullscreen mode Exit fullscreen mode

This will take you to the Ubuntu-18.04 shell. The * denotes the default distribution. What does that mean? To check run following command,

wsl
Enter fullscreen mode Exit fullscreen mode

This will take you to Ubuntu-20.04 shell without mentioning the distro. If you want to change the default distro run,

wsl -s Ubuntu-18.04
wsl -l -v
Enter fullscreen mode Exit fullscreen mode

You will notice the default distribution changed to Ubuntu-18.04.

NAME STATE VERSION

  • Ubuntu-18.04 Stopped 2 Ubuntu-20.04 Stopped 2

Now if you run,

wsl
Enter fullscreen mode Exit fullscreen mode

Ubuntu-18.04 shell will launch. To verify if the right version is launched. Run following command,

lsb_release -a
Enter fullscreen mode Exit fullscreen mode

You should get output similar to,

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic

Now open another PowerShell or command prompt window and run,

wsl -l -v
Enter fullscreen mode Exit fullscreen mode

You will notice Ubuntu-18.04 is in Running state. IF you close the wsl window or run exit the state will change to Stopped.

Alt Text

Hopefully this will get you started on WSL2. In my next articles we will use WSL for running tools supported on Linux environment.

Till then, happy coding!

Discussion (0)

pic
Editor guide