Windows Subsystem for Linux (WSL) is a way to run actual Linux inside Windows without the need to set up a virtual machine. The project has seen a ton of support, and WSL2 is the latest and greatest.
There is now a new, extremely simplified way to get WSL2 up and running on your Windows 10 and Windows 11 PC. The only requirement is that you’re running version 2004 of Windows 10 and above.
open up PowerShell and enter this command:
wsl --install
That’s it. The setup process will begin and you can relax until it’s finished.
How to enable Windows Subsystem for Linux
Before you can get WSL2, you need to have WSL. That may sound slightly strange, but the methods of enabling the first iteration and the second are quite different. But to have the newest version, you first need to have the first. There’s no direct path to just installing WSL2
After you have installed WSL (first step, above) , Open PowerShell as administrator and enter this command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Eventually, you will need to reboot your PC, but you can leave it until later if you’re going straight to installing WSL2.
PS: Now you have the Windows Subsystem for Linux enabled. It’s time to download and install WSL2.
How to install WSL2 on Windows 10
There are also a couple of pre-requisites for using WSL2 on Windows 10. You need to be on the following versions:
- For x64 systems: Version 1903 or higher, with Build 18362 or higher.
- For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.
If you have anything lower, you’ll need to run Windows Update before going any further.
Assuming that’s all good, the rest is straightforward. —> enabling Virtual Machine and install WSL2
Enabling Virtual Machine
If you don’t already have this enabled, you’ll need to turn it on before installing WSL2. As already stated, WSL2 is a tiny virtual machine, so Windows needs to be prepared for that. If you have this enabled already, skip and go straight to rebooting your PC to make sure you’re ready to install.
The quickest way to do it is in PowerShell. Open PowerShell as administrator and enter this command:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Downloading and installing WSL2
- Download the WSL2 Kernel update.
- Run the installer.
- When prompted for elevated permissions, click yes.
Once the installer has done its thing, you’ll now have WSL2 successfully installed on your PC.
Setting WSL2 for your Linux distros
The good thing about WSL2 is that it doesn’t replace WSL. It just runs alongside it. This means you can run Linux installs with a combination of different versions. You’re able to set either as default as well as setting a version specifically to each Linux distro you have on your PC.
Let’s see some of the key commands to use in PowerShell that you’ll need to know:
Setting WSL2 as default
If you want everything to run on WSL2 as soon as you install it, you can set it as the default version.
wsl --set-default-version 2
Listing installed Linux distros and their WSL version
With WSL2 set as default, any Linux installs after that will use it automatically. You can easily check which version of WSL your installed Linux distros are using.
wsl --list --verbose
PS: Using the verbose flag will give you the breakdown of which version of WSL is attached to which Linux installation. Without it, you’ll simply get a list of the versions of Linux you have installed.
Changing the version of WSL per Linux installation
While setting WSL2 as default will apply it to anything you install afterward. But, if you wish to go between versions 1 and 2 or run a mixture on your system, you can do that.
wsl --set-version <distribution name=""> <versionnumber></versionnumber></distribution>
So, as an example, if you have a Debian installation on WSL that you need to convert to WSL2, you’d enter
wsl --set-version debian 2
Launch specific Linux installations in PowerShell
If you only have one version of Linux installed, simply typing
wsl
in PowerShell will launch you into the associated bash shell. But if you have multiple, you can launch a specific distro with this command.
wsl -d <distribution name=""></distribution> // eg: wsl -d debian
Once you’re done, typing “exit” will take you back into PowerShell.
exit