These weeks at end of year are the perfect time to test out all the new goodies that have come our way over the last year. As an avid (15 year) Linux enthusiast I spent the last couple of days getting Linux up and running on Windows the modern way – through the fresh WSL2 (Windows Subsystem for Linux) delivered a couple of months back.
And here are my tips and take-aways.
Why would we want it?
Ok I’ll do this one first, quick. Why would we want a Linux subsystem in Windows anyway?
First, I’m still a developer. I develop in .Net core, NodeJS, Python, frontend projects and the occasional blockchain. Build scripts are notoriously more work if you need to support Windows, even when you convince Windows users to compile with bash. A simple example: even this doesn’t work on Windows:
[ -f “$FILE” ] | doSomething
Second, using docker. Personally, I have never started a Windows container. And to be honest, I can’t think of a reason to start. And to get access to all the Linux container goodness from the Docker repository you need a Linux host.
Understanding the hypervisor
To understand why WSL2 is nice to use, let’s look at what was there before:
- WSL1: a “Linux-compatible kernel interface” developed by Microsoft. It could be used to run programs on top of it, but nowhere near the native experience.
- Hyper-V: The Windows hypervisor for running virtual machines. Of course, you could run any VM here, including the Linux ones. It was available in the enterprise versions of Windows, not the Home edition.
- Docker for Windows: The tools for running containers. You have to choose either Windows or Linux containers, this selects the host. The host for Linux containers is a VM in Hyper-V.
Now fast-forward to WSL2, the most apparent changes that have been made are:
- Hyper-V has been split up. The hypervisor – knows as the “Virtual Machine Platform” – is available on all versions of Windows, including Home. The Hyper-V manager is still Enterprise-only.
- WSL2 is a scalable system, you can manage one or more VMs directly in your hypervisor. This gives you access to different Linux systems simultaneously. It is side-by-side to Hyper-V manager if you happen to install both.
- Docker for Windows can now run on a VM within WSL2 instead of Hyper-V, making Linux containers available to Home users as well.
Make sure you install the basics. You can go through step 1 – 5 of the Manual Installation Steps.
Accessing the correct VM
Now as I said, you can have more than one system available. One thing to understand is that Docker for Windows needs to have the default machine set to “docker-desktop”. My default installation looks like:
I installed the Ubuntu distro myself; the others were created. Now if you want to start the WSL command line every time within your own VM, change the link:
Note: it took me quite some time to figure out I was in the wrong machine, trying to “sudo apt-get update” within docker-desktop…
Choosing the correct distro
Not necessarily a topic for WSL2, but if you just want to use it you might get stuck choosing the right one from step 6 of the manual installation steps. Hopefully this helps a bit if you’re not familiar with the different Linux distributions (aka distros) out there:
- Redhat: An enterprise distribution of Linux which uses RPM as package manager, due to licensing this is not directly available on WSL2.
- Debian: An enterprise distribution of Linux which uses DPKG / APT as package manager, open and free to use.
- Suse: An enterprise distribution of Linux developed by SUSE.
- Fedora: The client version of Redhat, also using RPM as package manager. It is free to use.
- Ubuntu: Originally split off from Debian as a client version, so they could deliver more recent versions of packages, trading stability risk for functionality.
- Alpine: A minimal version of Linux, used as basis of many Docker containers.
In general Ubuntu is a very popular choice, especially since you’re most likely setting up a client system where you will want most recent versions available. However, you can install them side by side if you want.
Now why did we set it up? For me it was having all my Windows goodness with IDE and tools I’m so used to combined with a Linux system for building portable applications and having access to my code from both sides.
So, you need to know that your Windows drives are mounted in your Linux VM already. They are available in your default mount location, in the case of Ubuntu at least it’s:
Since the bulk of time I’ll be working in git repositories, I created a symbolic link so my repos directory is always available as /repos:
As a closing statement I would like to mention that this was my least painful experience with getting Linux up and running on Windows so far. It genuinely seems like Microsoft is embracing it, and I wouldn’t be surprised if Windows will become one more Linux Distro after all…
About Edwin van der Thiel
Freedom has been a guiding factor throughout Edwin's career, it drives his ambition and gives meaning, in different ways. In the form of Personal Freedom it's the ability for every person to be themselves. He embrace it in himself, in his development plan, building his career. To others he strives to be as open, fair and welcoming as possible, and defend each one's right to be themselves. In software freedom, through Open Source and Open Standards, He's a big advocate of the ideology. Not only in the open source community, but bringing the culture of openness and sharing wherever he works. Openness is the basis of trust, and it can be a guide to the future. Through freedom of teams, He's a big fan of Agile working. His vision on Agile is centered around the triangle of Trust, Responsibility and Commitment. It brings guidance on collaboration and enablement rather than focussing on processes, managers and templates. Freedom of data, or rather the ability to own your own data. Currently this centers heavily on Decentralization, Web3, Blockchain and the Metaverse. To him the important issue is on building an internet where everyone can be owner of their data, they control it, no governing platform, institution or country can take it. Much like the ideas in your head, you hold what's yours. He loves the south-american culture, in particular Brasil. In his spare time he is a husband to Jacy, father to Amy, a dancer and Capoeira instructor, and loves to explore the world.
More on Edwin van der Thiel.