WSL
Web development on Windows can be a frustrating experience, mainly because Windows is not POSIX compliant. As a result, web developers often favour macOS or Linux, which are POSIX compatible (even if Linux is not fully certified).
Since February, I have increased my usage of Windows, which has forced me to explore alternative approaches to support my common workloads (which includes web development). Historically, I have used a hypervisor and/or Docker to provide a viable development environment on Windows. However, each of these options can be frustrating, recognising that they are both reliant on virtualisation.
Therefore, I decided to explore Windows Subsystem for Linux (WSL), which is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10.
WSL provides a Linux-compatible kernel interface (containing no Linux kernel code), which supports a GNU userspace, such as Ubuntu, openSUSE, Debian, etc. The userspace provides access to a Bash shell, native GNU/Linux command-line tools and programming language interpreters (e.g. Ruby, Python. etc.) Microsoft does not promote the use of graphical applications, however, this can be partially accomplished using an X11 server running on Windows 10 (e.g. Cygwin X, Xming, etc.)
Due to the use of a compatibility layer (instead of a real Linux kernel), WSL has several limitations. For example, it is not capable of running all Linux software, specifically 32-bit binaries. It is also not possible to install kernel modules and device drivers.
The WSL architecture can be summarised into two parts:
-
LXSS Manager Service: The LXSS Manager Service interacts with the Windows Subsystem for Linux (via the drivers lxss.sys and lxcore.sys), allowing Windows to launch Linux processes, as well as handle Linux system calls and binary locks during execution.
-
wsl.exe: The wsl.exe command is used to manage distributions on the command-line. The command can also be used to run Linux binaries from the Windows Command Prompt or Windows PowerShell.
In my experience, WSL works reasonably well. Being able to access the Bash shell from within Windows feels a little strange, but is a step in the right direction for web developers. Unfortunately, due to the use of the “compatibly layer”, WSL is not perfect, limited system call compatibility and the relatively poor IO performance can quickly become a point of frustrating when working with complex web applications.
Recognising WSL is still fairly immature, I hope Microsoft continues to iterate on the architecture, potentially looking to include a full Linux kernel in a future release. This outcome would likely be seen as blasphemy by some Windows evangelists but would overcome the current limitations and potentially provide the best of both worlds (Windows + Linux). If successful, I could see Windows becoming a more popular/common option for web developers, providing a viable (and cheaper) alternative to macOS.
Getting Started with WSL
The steps outlined below, highlight how to install Windows Subsystem for Linux (WSL) using Ubuntu 18.04, without the use of a Microsoft Account or the Microsoft Store.
Open “Control Panel” and search for “Developers”. Enable “Developer Mode” by checking the box highlighted in the image below:
Open Windows PowerShell, ensuring that you select “Run as Administrator”.
Run the following command, which enables WSL.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Download the approved Ubuntu installation file from Microsoft, using the following URL:
- https://aka.ms/wsl-ubuntu-1804
Once downloaded, install Ubuntu.
Open the newly installed Ubuntu application.
Complete the installation by creating a username and password.
WSL is now fully installed and available for use. For more information regarding WSL, I recommend referring to the WSL Setup Guide.