Windows Subsystem for Linux
January 14, 2021 — November 23, 2021
Historically, there are a thousand small annoyances in getting software developed for Linux to run on Windows. Since 2020 or so, the number of annoyances has been vastly reduced by Windows Subsystem for Linux (WSL). WSL installs a miniature Linux distro backed by the Windows OS that runs within Windows. This means that I can copy-paste Linux setup instructions for my favourite software packages into a terminal on my Windows machine and have them run. For activities like cloud compute, which usually presume the cloud is made of Linux, this is extremely helpful since there is less likely to be a difference between installing my development environment locally and on the cloud.
Here are my notes on that.
There are two flavours of WSL: WSL1 and WSL2. I understand they are backed by different technology, the distinction between which has been written about in various places, and I am hoping I do not need to care about. tl;dr; everyone is using WSL2 now; I will do my best to learn nothing about WSL1.
1 Installation
Classic install procedures have changed a lot, so it is worth googling. At the time of publication, the Microsoft official instructions are now simply to run PowerShell as administrator and execute:
I find the Ubuntu explanation enlightening to understand what is actually going on:
1.1 Installing Ubuntu on WSL via the Microsoft Store (Recommended)
The recommended way to install Ubuntu on WSL is through the Microsoft Store.
The following Ubuntu releases are available as apps on the Microsoft Store:
- …
- Ubuntu 20.04 LTS (Focal) is the current LTS release, supporting both x64 and ARM64 architecture.
- Ubuntu (without the release version) always follows the recommended release, switching over to the next one when it gets the first point release. Right now it installs Ubuntu 20.04 LTS.
Each app creates a separate root file system in which Ubuntu shells are opened but app updates don’t change the root file system afterwards. Installing a different app in parallel creates a different root file system allowing you to have both Ubuntu LTS releases installed and running in case you need it for keeping compatibility with other external systems. You can also upgrade your Ubuntu 16.04 to 18.04 by running
do-release-upgrade
and have three different systems running in parallel, separating production and sandboxes for experiments.
2 Invocation
After installing, say, an Ubuntu distro, I have an ubuntu.exe
command. Cute! But slightly confusing. The wsl
command can launch many different distros and even launch into particular apps inside a distro. This app is a favourite of mine:
Each distro is effectively a separate customised virtual machine, AFAICS. This conflates the idea of the virtual machine and the software which runs on the virtual machine to my mind, but maybe this confusion is OK for the current purposes. Or maybe advanced users can disentangle these.
3 Compatible terminals
Windows and Linux use different terminal standards, so if you are not satisfied with the built-in terminal emulation (I am not), you need to install a terminal app which runs on Windows but understands POSIX. Pro tip: Cmder supports both Windows and POSIX conventions.
4 X GUI
I hear reports that WSL GUIs run for some apps if you have an X server. I suspect this is not officially supported? Anyway, worth trying. It will need a Windows-compatible X-server, I suspect. Here are two options that were mentioned in the chat at work:
- Cheap commercial X-server: X410
- Open source alternative: VcXsrv Windows X Server download