How to install WSL2
I have used Linux for half of my career experience. When I need to develop some new services using Windows the first what I do is install the WSL2 and Ubuntu to be able to use Linux Terminal and file system.
Preparation
First of all your computer has to have Hyper-V Virtualization support.
Let’s open PowerShell and execute the following command:
systeminfo | Select-String "^OS Name","^OS Version"
We should to see the details about version of you OS:
OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.22000 N/A Build 22000
Here we are interested in the OS Version it has to be higher than Windows 10 1909.
As we can see, in my case it is higher, so I can proceed following this guide otherwise if you have Windows 10 1909 or older scroll down to the section when I’m describing how to Install WLS2 for Windows 10 1909 or older.
Installation of WSL 2
Open Command Prompt as Administrator and execute the following command:
wsl --install
After, reboot your PC to finish WSL2 installation.
Installation of specific distro
To install the distro on your Windows OS through WSL2 you have to open Command Prompt as Administrator and execute the following command to see the list of available distobutives:
> wsl --list --online
The following is a list of valid distributions that can be installed.
Install using 'wsl --install -d <Distro>'.
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
openSUSE-42 openSUSE Leap 42
SLES-12 SUSE Linux Enterprise Server v12
Ubuntu-16.04 Ubuntu 16.04 LTS
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Next, just choose needed distro and execute installation:
wsl --install -d Ubuntu-20.04
Restart your computer and enjoy.
Update WSL2
If you have already installed WSL2 you could easier to update it. Open Command Prompt as Administrator and execute the following command:
wsl --update
After, you have to restart your WSL2 using:
wsl --shutdown
WSL2 updated!
Installation of WSL 2 (Build 1909 or older)
Firstly, you have to enable Support WSL feature, for that we should enable it. Open Command Prompt as Administrator and execute the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
After, you have to reboot your PC.
Second step is enable Virtual Machine Platform. To do that open Command Prompt as Administrator and execute the following command:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Now we are ready to activate WSL 2:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your PC.
So, now we are ready to install WSL 2, as usual open Command Prompt as Administrator and execute:
wsl --set-default-version 2
We are done!
Installation distro using Microsoft Store
Open the Microsoft Store and in the search input type “Ubuntu” or the name of preferred distro.
Click “Get” for a chosen distro and enjoy.