Development

Windows Subsystem for Linux

The Windows Subsystem for Linux (WSL) enables developers to run a Linux system directly on Windows. This is done without the overhead of a traditional virtual machines.

WSL is primarily intended for developers. This allows developers to use Bash, common Linux tools and many Linux-first tools and frameworks (Ruby, Python, etc.) on Windows.

In this blog post I will show how to install WSL and its basic usage.

Installation

First, I enabled Windows Subsystem for Linux feature on my Windows 10 box. I can do this by using PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

or via Windows Programs and Features -> Turn Windows features on or off:

After I enabled WSL feature on my system, I installed Linux distribution (subsystem) to work with. For me, Ubuntu is the most familiar Linux distribution, so I picked Ubuntu to be my WSL distribution. I installed Ubuntu 18.04 LTS via Microsoft Store, e.g.:

This is only my customization, but before usage, I just add WSL Ubuntu shortcut to my Windows Terminal.

How to add new console shortcut to the Windows Terminal is out of the scope of this blog. Here, I will just paste my Windows Terminal profile I used, but it’s on you, dear reader, to figure it out how to put new tab shortcut into Windows Terminal.

Let’s play

Everything is on place. Next, I will quickly present usage of WSL on simple examples.

Native host c/c++ compile

I have simple c file on GitHub for experimenting (link here). Let’s try to compile using WSL. Beforehand, I installed (using apt-get) gcc compiler.

Awesome, everything works just fine!

Just quick overview of my super-complex, super-awesome c code :):

Compile and run .NET Core Console app on Linux

.NET (Core/Framework) is my preferred development ecosystem. So, of course, I was eager to try some experiments with C# and .NET Core. For that purpose, I installed .NET Core to my Ubuntu WSL, then I tried simple console app.

I just made small modification to Program.cs file, of course with usage of nano editor!

Simple, super fast and fun!

Asp.Net Core web application on Linux accessed from Windows

I crated simple Asp.Net Core web application inside WSL and I will try to access it from browser on my host machine (Windows).

Because WSL and Windows share the same ports, I can access application from my Windows.

Nice, what else can I say!

Linux to Windows interoperability

It’s almost unbelievable how easy it is to share/access programs and files from one system to another. For example calling windows application from WSL Ubuntu console is a breeze.

Windows to Linux interoperability

Using Linux commands inside windows console is even easier: I just put wsl before command, e.g.

Conclusion

With WSL, switching between Linux and Windows command toolsets is easy, “resource cheap”, and super fun.

For me, having Linux Virtual machine running (or on stand by) was always an overkill. I never used it, because startup times were killing me, VM took to much resources, virtual machines were isolated, etc… So, switching between Linux and Windows in this way never worked for me.

But with WSL this changed. Now, I have fast, low resource foot-print, easy and integrated way how to switch between Linux and Windows tool-chains on my Windows host. That’s really amazing.

And yes, it’s about time to uninstall Cygwin from my Windows!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.