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,
You will be able to see the build version of your windows e.g. 1903.
Download the installer for the WSL2 kernel from,
Run the installer to install WSL2 Kernel for Linux. Once the installation is successful. Open PowerShell or command prompt and run,
This will list all the distros and the version of WSL in the version column. The list will look somewhat similar to this,
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,
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,
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,
Ubuntu-18.04 shell will launch. To verify if the right version is launched. Run following command,
You should get output similar to,
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
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.
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!
Top comments (9)
Thanks! Worked like a charm
Thanks for the amazing article, I've put upgrading for months because I thought it was going to delete all the distro files, but after reading the article and your experience, I went for it, and all is good.
what if i upgrade wsl1 to wsl2, will i lost the other downloded tools like GCC, valgrind,gdb?
None of my files were lost in the process, so I assume it will retain the tools. However I am not so sure on this one, but you can always reinstall the tools.
Thanks a lot brother, you've help me..
Firstly, I little confused read official docs about this topic. until I found this
Excellent Article !
thanks... it took around 10-15 minutes here
NOTE: if you have configured docker for WSL 1, and now you're upgrading make sure to remove the DOCKER_HOST variable from your Linux distro config
Thanks Aditya it's help a lot