How to install WSL2 on Windows 10
June 07, 2021
This is the first post of a series that aims to explain how to get a fully productive and integrated Linux development environment within Windows 10. Today, I will explain what is WSL 2 and how to install it on Windows.
But first what it's first. What is WSL 2? The Windows Subsystem for Linux (WSL) lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications such as bash, ssh, sudo, apt, curl, etc. -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or the extra disk space needed for a dual boot setup.
WSL 2 is a new version of the Windows Subsystem which primary goals are to increase file system performance, as well as adding full system call compatibility. The Linux kernel is executing in parallel to the Windows one, in a very light hypervisor (a low resource consuming virtual machine).
If you are interested in learning more about what is WSL and what does, along with the differences between version 1 and 2, you can check the official Microsoft docs.
First, your Windows 10 build version should be 1903 (also known as 19H1) or above. This is a version from May 2019, so if you have auto updates enables, it is highly probable that you are using a compatible Windows 10 build.
If you want to check what your current Windows 10 build version is, just run
winver and a window will open with the basic version info.
Next, we will enable the WSL feature on our Windows. For doing that, open a new PowerShell instance as administrator. Just search for
right click -> execute as administrator. There, we will execute the following command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Now, we must enable the Virtual Machine Platform feature to WSL for proper working, by executing:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
At this point we should restart our Windows to apply changes. Once we are back in our user, we need to set WSL version 2 as our default WSL version. For doing that, open a new PowerShell terminal (doesn't need to be an administrator privileged terminal) and execute the following command:
wsl --set-default-version 2
Congratulations!`You have already installed WSL 2 in your machine. It wasn't so difficult, wasn't it? Just a few terminal commands.
The next step is to install your Linux distribution of choice. To do so, just open the Microsoft Store app on your Windows and search for
Personally, I installed Ubuntu for the following subjective reasons:
- Canonical (the developers of Ubuntu) and Microsoft have a partnership to ensure maximum stability and compatibility of the Ubuntu WSL images.
- Most of Linux user out there use Ubuntu, so it is easy to find resolution to the majority of problems, because chances are that someone had the same problem before you.
- As a developer (my Linux geek times went away years ago) I want to expend the less time possible solving problems with my environment, so the above two points are important to me.
However, you can use, as I said, the distro of your choice. I will use Ubuntu for the rest of the series, but the steps should be equal or very similar to all the WSL available Linux distributions. Just chose one and select "Get" on the Store.
The first time you launch a newly installed Linux distribution, a console window will open, and you'll be asked to wait for a minute or two for files to decompress and be stored on your PC. All future launches should take less than a second.
You will then need to create a user account and password for your new Linux distribution. This will be a user with sudo privileges. The onboarding script will guide you through this process, but if you have some doubts or want to know more, here is the official Microsoft docs that explain it very well.
Hope you have found this post useful. Cheers!
(You can find comments to this article in dev.to)