Coming in as a successor to WSL 1, it was created to provide the user a noteworthy boost in performance and better system compatibility. WSL 2 offers a variety of improved features, the most striking of which are:
- Having a managed Virtual Machine (VM)
- Allowing for full system call ability
- An in-built Linux Kernel
These features are the crux to what makes the switch from WSL 1 to WSL 2 a desirable experience.
Before we begin, we need to make sure that we have Windows 10 updated to either version 1903 with OS Build 18362 or higher (for x64 systems) or Version 2004 with OS Build 19041 or higher (for ARM64 systems). You can check your Windows version by typing winver in the search box next to the Start button.
If you are running an older build of Windows 10, you can update it by navigating to Settings > Updates and security > Check for updates.
You also need to ensure that your device offers adequate support for Hyper-V virtualization, which you can determine by typing Msinfo32.exe in the search box and checking your system information.
Having done that, we can begin the installation process.
Step 1. Initializing WSL
This is a crucial step to install either version of WSL. We can initialize WSL by using simple console commands.
Click on the Start button and search “Windows PowerShell”. Right-click on the first result and select Run as administrator. A console window should now appear.
Enter the following command line in the console and press enter:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
The output should look something like the image below.
Step 2. Initializing VM Platform
Unlike WSL 1, WSL 2 uses an in-built kernel. For this reason, we require the use of a Virtual Machine Platform.
Like what we did for WSL in step 1, we will run commands in Windows PowerShell to enable Virtual Machine Platform.
For Windows 10 (2004 edition):
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
For Windows 10 (Version 1903, 1909):
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
After completing both steps 1 and 2, it is recommended to restart your device to apply changes correctly and make sure that everything works as intended.
Step 3. Configuring WSL 2 as default
After restarting your device, run Windows PowerShell as an administrator and type the following command:
In some cases, the console will ask you to update your WSL kernel. The prompt should look something like this:
You can download the update by visiting the link in the image above or by clicking here (for x64).
Once you are done installing, run the command again, and the default version should now be set to WSL 2.
Step 4. Install a Linux distro
Now that we are done with configuring WSL 2, it is time to install a Linux distro. Here you have a wide variety of options to choose from, each with its pros and cons. Currently, one of the most popular distros – Ubuntu 20.04 LTS – is an open-source OS that caught major traction in the Linux community. Other options include Kali Linux, Pengwin, and Fedora Remix for WSL, but it is a matter of preference more than anything.
For the sake of simplicity and wide accessibility, we will proceed with using Ubuntu 20.04 LTS as the Linux distribution for the upcoming steps.
Step 5. Getting started with WSL 2
Having installed the distro of your choice, you can access it from the recently added icons in the Start menu. Click on the icon to open Ubuntu to start the installation process. This will take a while since it is booting up for the first time, extracting all required files and packages. Make sure not to turn off your device during this process. Once it finishes booting up, you will be prompted to enter a username and a password. Fill in a username and password that you find suitable. Having done that, you are now ready to use WSL 2.
An alternate method to enable WSL and VM Platform (Optional)
Those of you who struggle with working on the console and are more accustomed to GUI-based configurations have the option to enable WSL and VM Platform manually. Follow the steps below to enable these features.
Firstly, click on the Start button and search for “Turn Windows features on or off”. Click on the first result. A new features window should open.
Scroll down and look for “Virtual Machine Platform” and “Windows Subsystem for Linux” options. Check the box to the left of the names to enable them and click OK.
Windows will now install the required files, after which it will ask you to restart your device to apply these changes. After the restart, proceed as instructed from Step 3 and onwards.
- You can switch back to WSL 1 by typing wsl –set-default-version 1
- If your device lacks Windows 10 or Hyper-V compatibility, you can still use WSL 1
With WSL 2 finally installed and configured, you are ready to experience the best Windows-Linux integration. You now can do all your Linux-related development without leaving the comfort of Windows 10 or going to great lengths by dual-booting your PC. Hopefully, with the ease of using Linux applications and executing Linux commands at fast speeds and optimized performance, your experience will be nothing short of gratifying.