Upgrading from WSL1 to WSL2
Tags: windows, wsl2, linux, wsl
Published: 2020-11-19 17:45:49

#Background

In my last [post](https://dev.to/adityakanekar/developing-for-linux-environment-in-windows-10-with-wsl-2-part-1-4422) 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](https://docs.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2) To check windows version, click Windows + R Key and type,

```
winver
```
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 
```

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](https://dev-to-uploads.s3.amazonaws.com/i/6dcvq9ii5jd69kguhcck.png)       

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
```

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
```

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
```

You should be able to see output similar to,

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/16gx3k3j76x3nug76fuu.png)

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

```
wsl -d Ubuntu-18.04
```

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
```

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
```

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
```
Ubuntu-18.04 shell will launch. To verify if the right version is launched. Run following command,

```
lsb_release -a
```

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
```
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](https://dev-to-uploads.s3.amazonaws.com/i/noflz0zko9sxfqfos9ay.png)

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!