You already have Linux. It’s inside Windows.

Yasser Douslimi
ENSIAS IT
Published in
5 min readDec 24, 2020

You heard it a thousand times. You must get Linux to be a “real” programmer. If we ignore the gatekeeping for a second, this is also a harsh statement toward the Windows OS. After all, Microsoft Windows is not just dominating the desktop ecosystem with ~78% market share for nothing. It must have its merits too.

But guess what? That doesn’t even matter because Windows has had the Linux kernel built-in for a while now. This means that it can exploit all of Linux’s functionalities without using any external software.

You may be saying now that, “so what? I already have a virtual machine, so this is useless to me…” It’s true, virtual machines do incorporate outside operating systems and give you the luxury of using both. However, have you ever considered that virtualizing an entirely separate machine inside yours might be a little bit inefficient? Virtual machines do have their use cases, but they can be extremely bulky and slow at times especially when you just want to use a quick command for your Linux class.

Enter WSL (Windows Subsystem for Linux) that offers bare-bones Linux capabilities and lets you download a distribution like an app.

Linux Distros in Windows Store

What’s WSL?

WSL or more accurately WSL2 (current version) is a compatibility layer that enables Linux to run inside Windows equipped with a filesystem and everything it needs to operate.

While you can bypass this with xrdp, this system only provides a terminal experience which is arguably all you need if you’re a developer to begin with.

The roots of this project go all the way to 1993 when Microsoft launched the POSIX subsystem inside their older Windows releases which were still in their infancy and had other purposes at the time.

Today, however, WSL2 provides a full Linux experience and it’s receiving regular updates. It’s unfortunately not open-source because if it was, Windows as a whole would have been open-source as a result, but it does have a GitHub repository where they receive regular issues and focus on fixing them as if they were emulating open-source.

How do I install this?

First off, you might want to check your current windows version and see if it’s higher than 1903. The build must also be higher than 18362. Otherwise, a simple windows update should get the work done. You can easily check by pressing WIN+R and typing “winver”.

Fast Install

Next up, the team included a simplified method to install it, but you need join the Windows Insider Program to use it. Simply type this into a command prompt with administrator privileges.

wsl –-install

Manual Install

For those who don’t want to use an insider build, the first thing you should do is enable WSL in your machine by executing this command in PowerShell.

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

Now restart your computer. You should have WSL2 enabled by now. Next up is enabling the virtual machine platform feature with this command in PowerShell.

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

Next thing is to download the kernel update package from Microsoft. You can get it from here.

Now you can simply set the default version number to 2 with this command.

wsl --set-default-version 2

All that’s left now is to install a distribution from the windows store and you’re good to go. I recommend ubuntu.

How do I use this?

If you installed ubuntu you can now run it easily by typing ubuntu in any terminal window.

You can also run it like an application and pin it to your taskbar.

Awesome things you can do

Manipulate your windows filesystem with Linux commands

We can try to find my illustrator projects and pipe the result into a text file. The catch here is that we’re doing this with our windows files. You can go wild with this and experiment to your heart's content.

Note: You can access Windows folders from the /mnt directory.

Go crazy with apt-get and Linux packages

We all know that the strength of Linux comes from its infinite packages. You can exploit them directly from windows with any terminal. I recommend the Windows Terminal app from the store. It synergizes really well with WSL.

Code programs as if you were in Linux in vscode

C developers know it. There are so many libraries in Linux that you have to be out of your mind to code C programs in Windows. Yet, it’s finally here.

We can test this using fork() and check if a multiprocessing program compiles and runs on windows.

Power up your docker workspace with native Linux containers

This snippet from docker’s official documentation says it best.

Windows Subsystem for Linux (WSL) 2 introduces a significant architectural change as it is a full Linux kernel built by Microsoft, allowing Linux containers to run natively without emulation.

Conclusion

Who thought that using Windows wasn’t so bad after all? The shift that Microsoft had as a company in the last few years has been really refreshing as they embrace open source more and more. Ever since this shift in philosophy, they’ve produced and helped grow many products that are cherished by developers around the world such as visual studio code or even the GitHub platform.

Their open front to Linux has been welcomed by developers very strongly and rightly so. Now it’s your turn to join us and get the best of both worlds.

--

--

Yasser Douslimi
ENSIAS IT

Aspiring software engineer. Curious about everything tech.