The Windows Subsystem for Linux (WSL) is a great solution for users and developers to natively work within Linux right on their Windows 10 desktop. Go ahead and learn everything you need to know about WSL 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 was announced at Microsoft Build 2019. It features a Linux kernel running inside Windows 10 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 WSL in Windows 10
To install Windows Subsystem for Linux on Windows, 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.
How to install WSL1 from the Command Line
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
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
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.