Microsoft introduced WSL (Windows Subsystem for Linux) in 2017, which provided the users to run different Linux Commands and other tools in a command-line interface on a Windows PC (without using HyperV or dual boot).
In 2019, Microsoft announced the release of a new version of WSL, and it was named WSL 2. This new version of WSL supports running graphical Linux apps on a Windows PC and utilizes a fully-operational Linux kernel with better file I/O performance and faster system calls. Another excellent achievement in WSL 2 as it is supported on the Home version of Windows 10, whereas, WSL only supported Windows 10 Pro.
Requirements to Enable the WSL Feature
A user’s PC must meet the following requirements to enable the WSL feature:
- Support Hyper V
- 64-bit version of Windows
- Windows 10 version 1903 or higher. In the case of an ARM machine, Windows 10 version 2004 or higher. Windows 11 natively supports WSL 2.
If your PC does not meet these requirements, then you may have to use WSL 1 version only and you may follow the guidelines below but skip the parts related to WSL 2 (like setting the default version to WSL 2).
If your PC meets the system requirements of WSL 2, you may follow the guidelines discussed below:
Install the WSL Through PowerShell
Microsoft has made it easier for its users to use a single PowerShell command to install the WSL feature along with the default Ubuntu installation (that can be changed). This PowerShell command will enable the required WSL component, download and install the latest Linux kernel, set WSL2 as the default, and install Ubuntu. So, follow the steps below to set up WSL with a single command (this command is supported only on Windows 10 2004 or above):
- Right-click Windows and select PowerShell (Admin).
- Now execute the following:
- Wait till the installation process of all the components is complete and then reboot your PC.
- Upon reboot, you may set up the Ubuntu distribution as per your requirements (discussed later) and you are ready to explore the wonders of Linux.
You may use the Ubuntu app in the Windows Start menu or use the Windows Terminal app to explore different Ubuntu features.
Install a non-Default Linux Distro Through the PowerShell Command
What if a user wants to install a different distribution than the default Ubuntu? So, don’t worry, here is a simple process:
- Open the Windows PowerShell (Admin) and execute the following to check the list of available Linux distros for WSL:
wsl --list --online
wsl -l -o
- Now, check the list of available Linux distros and find which one fulfills your requirements. Usually, the following may be shown as available:
Ubuntu Debian kali-linux opensuse-42 SLES-12
- Then, execute the following command to install the required Linux distro (make sure to replace the <Distribution Name> with the distro name:
wsl --install -d <Distribution Name>
For example, to install Debian, you may use the command:
wsl --install -d Debian
- Now, wait till the installation is complete and restart your system.
Upon restart, set up the Linux distro as per your requirements (as discussed later).
Install a Custom Linux Distro
There can be users who may need to use a Linux distro that is not available in the Microsoft Store and those users may use the official Microsoft reference page to import any Linux distribution to use with WSL as discussing it here is not in this article’s scope.
Install Multiple Linux Distros in WSL
If a user wants to use multiple Linux distros, he can do the same by using the (already discussed) following command in the PowerShell (do not forget to replace the <Distribution Name> with the distro name e.g., Debian)
wsl --install -d <Distribution Name>
In case multiple distros are installed, a user may check installed WSL distros in WSL by executing any one of the following in the PowerShell (Admin):
wsl -l -v
wsl --list --all
Keep in mind that if you are trying to execute the WSL command in the bash, then make sure to enter .exe at the end of WSL, for example, to install a Linux distribution from within the bash, execute the following:
wsl.exe --install -d <Distribution Name>
Install WSL on a Server
If you are installing WSL on a server machine, then you can reference the Official Microsoft Windows Server Installation Guide of WSL.
Installing WSL in a VM-Based Windows
If a user is installing the WSL feature in a VM-based Windows, then he may execute the following in the host’s PowerShell (Admin) to expose the virtualization flags of the host to the VM:
Set-VMProcessor -VMName MyWSL -ExposeVirtualizationExtensions $true
Confirm the Installation of Linux Distribution and WSL Version
Now, to confirm if the Linux distributions are successfully installed and the WSL version is set to WSL 2, a user may execute the following (one by one) in the PowerShell (Admin):
wsl.exe --list --all wsl --list --verbose
Use the GUI Method to Install WSL
Many Windows users do not prefer a command-line method to install applications/utilities. Also, WSL version 1 cannot be installed by using the single PowerShell Command discussed earlier. Moreover, the users with Windows 10 version 1903 and 1909 cannot use the WSL install method. So, here is a more GUI-based method to use WSL on a Windows PC.
Enable the WSL Feature on Windows 10
- Click Windows, search and open Turn Windows Features on or off.
- Now enable the following two by check-marking the related checkboxes:
Virtual Machine Platform Windows Subsystem for Linux
- Then click on the OK button and let the system download/install the related files (make sure an Internet connection is available).
- Once done, restart your system.
The Windows Subsystem for Linux (WSL) can also be enabled by executing the following in the PowerShell (Admin):
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
The Virtual Machine Platform can be enabled by executing the following in the PowerShell (Admin):
For Windows Version 2004 or higher:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
For Windows Version 1903 and 1909:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
Download and Install the Latest Kernel Update of WSL
After enabling the required features, a user must update the WSL kernel.
- Download the latest WSL kernel update from Microsoft. The users with the ARM64 machines may download the ARM64 WSL Package.
- Once downloaded, right-click on the downloaded file, select Run as Administrator, and follow the prompts to update the WSL kernel.
Set the Default Version of WSL to WSL 2
After updating the WSL kernel, a user must set the default WSL version to 2. But before that, check which version of WSL is set as default by executing the following in the PowerShell (Admin):
wsl -l -v
If WSL 2 is not the default, then open the PowerShell (Admin) and execute the following:
wsl --set-default-version 2
This will change the WSL for all new installations of Linux distros to WSL 2. If a user has already installed a distro with WSL, he may execute the following (make sure to replace the <DistributionName> with the distro name) to change its WSL version to 2:
wsl --set-version <DistributionName> 2
wsl --set-version Ubuntu 2
Install a Linux Distro from the Microsoft Store
After setting up the default WSL version to 2, a user must install a Linux distro.
- Click Windows, search, and open Microsoft Store.
- Now search for the preferred Linux distribution. The following is the list of available Linux distros:
Ubuntu openSUSE Leap 15.1 SUSE Linux Enterprise Server 12 SP5 Kali Linux Debian GNU/Linux Fedora Remix for WSL Pengwin Pengwin Enterprise Alpine WSL Raft (Free Trial)
- Once selected, open the desired Linux distro and click on Get.
- Then click on Install and let the distro install (e.g., Ubuntu).
- Afterward, restart your system and configure the distro as discussed in the next step.
Configure the Linux Distro After the Install
- Once the Linux distribution is installed, launch it (either from the Start menu or from a command-line tool) and a Command Prompt window will be shown.
- Now, enter a user name (in lowercase) for the Ubuntu (this can be different from the Windows credentials).
- Then enter a password for the Ubuntu account and afterward, confirm the password.
- Now use the different Linux commands as per your requirements.
- To exit the Ubuntu bash, execute Exit in the bash.
Methods to Open a Linux Distro in WSL
There are several methods to open an installed Linux distro in Windows:
- You can type the Linux distro name in the Windows Start menu and launch it from there.
- From the Windows Command Prompt or PowerShell after typing the distro name (like Ubuntu) and hitting Enter.
- Execute WSL.exe in the Command Prompt or PowerShell to open the Linux terminal in the current shell or use wsl [command] to execute the WSL command. In the case of multiple distros, a user can configure the default distro by executing the following:
wsl -s <DistributionName>
wsl -s Debian
- To open a specific WSL distro, a user may execute the following in the PowerShell (Admin):
wsl -d <DistributionName>
- Last but not least and our favorite: Windows Terminal.
Install the Windows Terminal
Windows Terminal is a Microsoft terminal emulator that supports multiple tabs and is a replacement for Windows console. The usage of WSL becomes very easy with the Windows Terminal. To Install Windows Terminal:
- Open the Microsoft Store and search for Windows Terminal.
- Now click on Get and then click on Install.
- Once installed, launch it and use it to execute the WSL commands.
Update the Linux Distros and Kernel to the Latest Build
After configuring the Linux distribution, the first step should be to update it as Microsoft does not auto-update these distros. To do so, execute the following in the Linux bash:
sudo apt update && sudo apt upgrade
To update the WSL kernel, execute the following in the PowerShell (Admin):
To check the general status of the WSL, execute the following in the PowerShell (Admin):
Install Common Linux Packages
Once the distro is updated, a user may want to install different Linux packages in WSL. A user may use the APT package repository and execute the following in the bash (e.g., to install htop):
$ sudo apt install htop
And htop can be launched by executing the following in the bash:
To install GUI Win-Kex for Kali-Linux, a user may execute the following (one by one) in the bash:
sudo apt update sudo apt install -y kali-win-kex
Once installed, you may run Win-Kex in different options. The details can be found in the Official Kali documentation.
WSL and Windows File System
Where are the Linux files located in Windows? A natural question comes to a user’s mind. WSL has its File System installed on the following location (do not change or delete files in the directory):
During usage, a user may have to access the host’s file system in WSL. To do so, execute the following in the bash:
Enable the WSL1 Feature
There can be times where a user requires to install WSL1 (not WSL2) and to do so, simply follow the above steps, just skip WSL parts. To change the default WSL, a user may execute the following in the PowerShell (Admin):
wsl --set-default-version 1
Afterward, the user may install a new Linux distro to fulfill his requirements (as discussed earlier).
If the WSL version cannot be changed to 1, execute the following in the PowerShell (Admin):
New-ItemProperty HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss DefaultVersion -Value 1 -Force
Then, reboot your system and upon reboot, disable the Virtual Machine Platform. Afterward, your system is configured to use WSL 1.
Remove WSL and Linux Distro from the System
If you are done with WSL and want to remove it from the system, a simple process to do it is:
- Right-click on Windows and open Apps & Features.
- Now expand the Linux distro (e.g., Ubuntu) and click on Uninstall.
- Then, confirm to uninstall the distro and reboot your PC.
- Upon reboot, disable the Virtual Machine Platform and Windows Subsystem for Linux (as discussed earlier) in Turn Windows Features on or off.
- Now reboot your PC and upon reboot, the WSL is removed from the PC.
So, that’s it, we hope that this article has served its purpose and cleared the basic ideas of WSL.