Windows Subsystem for Linux Explained, WSL & WSL2

Windows Subsystem For Linux Explained, WSL & WSL2

The Windows Subsystem for Linux (WSL) is a great solution for users and developers to natively work within Linux right on their Windows 10 or Windows 11 desktops. Go ahead and learn everything you need to know about WSL and WSL2 in this guide.

Many users and developers have struggled to work on Windows systems with tools that either perform better on Linux or are not available on Windows at all. Solutions often involved installing a Linux distrbutions on a virtual machine, on a separate hard drive and configuring dual boot, or using tools like Cygwin. However, this is about to change as Microsoft introduced Windows Subsystem for Linux.

You may not be aware of it, but 93% of servers in the world are running on Linux. Linux systems are known to be very fast, reliable and secure. Software developers and system adminstrators love Linux because of its infinite customization possibilities, performance, and specialized tools that are not available on other systems.

What is Windows Subsystem for Linux

Windows Subsystem for Linux (WSL), is a compatibility layer for running Linux binaries in Windows environment. It was first introduced by Microsoft in Windows 1607. It is now included by default in Windows installations, you just have to manually turn it on.

Above all, the WSL lets users and developers run a GNU/Linux environment. It including most command-line tools, utilities, and applications directly on Windows. They are unmodified, without the overhead of a traditional virtual machine or dualboot setup.

WSL or C:\Windows\System32\wsl.exe is a Windows tool that allows you to install a Linux distribution as an app from the Windows store. Since WSL is a simple Windows executable, you can call it from a cmd command prompt or PowerShell terminal.

WSL and WSL2

There are two different versions of Windows Subsystem for Linux, WSL and WSL2.

The original WSL is now known as WSL1. WSL1 provides a Linux-compatible kernel interface developed by Microsoft that allows a user to choose a Linux distribution to install from the Microsoft Store. WSL1 executes unmodified Linux ELF64 binaries by operating a Linux kernel interface on top of the Windows kernel in Windows 10. 

WSL2 is the latest version of WSL with new features. It was announced at Microsoft Build 2019. WSL2 features a Linux kernel running inside Windows 10 and Windows 11 and is built on the core technology of Hyper-V to provide better Linux application support and improved file performance. WSL2 architecture is entirely different from WSL1. Unlike WSL1, which runs as a translation layer, the Windows subsystem for Linux 2 has a virtual machine with an actual Linux Kernel that can immediately react to system calls.

The main difference between them comes down to system call. In other words, WSL2 works a lot more like a traditional virtual machine (VM) where Windows would be the host and the WSL distro is the VM guest.

How to install Windows Subsystem for Linux on Windows 11

To install Windows Subsystem for Linux on Windows 11 with Command Prompt, follow these simple steps:

Open Start on WIndows 11 and search for “Command Prompt“. Then, right-click the top result and select the Run as administrator option.

Type the following command to install the WSL on Windows 11 and press “Enter“:

wsl --install

After installation is completed you need to restart your computer to finish the WSL installation on Windows 11. Now, you can continue with the Linux distro setup as necessary. This will install automatically the latest version of the Ubuntu Linux.

If default Ubuntu is not to your liking, there is a separate command that allows you to specify a preferred Linux distro during WSL installation. Here’s how to do it.

Open Start on WIndows 11 and search for “Command Prompt“. Then, right-click the top result and select the Run as administrator option.

Type the following command:

wsl --list --all

That will list all Linux distros available for download.

Find the distro you want to set up alongside WSL and type:

wsl --install -d [DISTRO-NAME]

Of course, you need to replace [DISTRO-NAME] with the name of the distro you want to install, for example, Debian.

Now, just hit the “Enter” key and wait for Windows 11 to install WSL and complete the process.

After installation is completed, restart your computer.

How to install Windows Subsystem for Linux on Windows 10

To install Windows Subsystem for Linux on Windows 10, the only requirement is that you have a 64-bit Windows 10 device. Different versions of WSL require different builds of Windows, but they can run alongside each other.

You need to run Windows Build 16215 or later to install WSL1. WSL2 is only available in Windows Builds 18917 or higher.

To check your build, from the Windows GUI, go to Settings -> System -> About.

Check Windows Build Number

How to install WSL1 from the Command Line on Windows 10

Open PowerShell (as administrator) and type:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Then, you need to restart computer when it is asked.

How to install WSL2 from the Command Line on WIndows 10

Firstly, we need to enabling the Virtual Machine Platform optional component on Windows. Therefore, we open our PowerShell console as Administrator and type:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Then, we enabled the WSL with this command:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

After that, we restart our machine.

When the machine is ready, we need to download and install the WSL 2 Linux kernel update package, available on this link.

In addition, to configure our machine to use WSL 2 by default, we open our Command Prompt as Administrator and we type:

wsl --set-default-version 2

Conclusion

It appears that the WSL is going to be a crucial component of Microsoft’s new open-source friendly strategy. Now you know how to make use of the Linux ecosystem on Windows. I hope you found this article useful.

Leave a Reply

Your email address will not be published.

Latest from Tutorials