Why Developers Should Install WSL Today

Premier Developer

Premier

In this post, App Dev Managers Matt Hyon and August Banks spotlights the developer benefits of WSL.


You’ve just finished installing the Windows Subsystem for Linux (WSL) on your Windows 10 computer and feel pleased to see your favorite Linux distro icon pinned to your taskbar. You click to open a shell session and think, “OK, what can I do with it?”. It’s a common thought for those kicking the tires more out of curiosity than with a specific purpose in mind, especially since there are many tools available natively on Windows to accomplish similar tasks, PuTTY for instance. So, we reached out to the extended WSL product team and advocacy team to get their insights into some of the compelling uses of WSL for developers.

WSL Background and Supported Linux Distros

WSL is a new feature of Windows 10 (1607 and later) that enables you to run Linux distros directly on Windows 10 alongside your favorite Windows applications. It has several advantages over a virtual machine instance in that it uses very little resources (comparatively) and is highly integrated into the desktop experience. Previously it was known as “Bash on Windows“ but it has grown to so much more.

WSL Linux distributions are available from the Windows Store.  Links and descriptions of support distros are listed below.

  • Ubuntu – Allows one to use Ubuntu Terminal and run Ubuntu command line utilities including bash, ssh, git, apt and many more.
  • Debian GNU/Linux – A complete Debian command line environment for the current stable release (9/stretch) – Debian Wiki
  • Kali – An open-source penetration testing and ethical hacking distribution. – Kali Blog
  • openSUSE Leap 42 – A stable, easy to use and complete multi-purpose Linux distribution. – SUSE Blog
  • SUSE Linux Enterprise Server 12 (SLES) – A world-class, secure open source server operating system, built to power physical, virtual and cloud-based mission-critical workloads. – SUSE Blog

Much more than a shell

It’s not immediately apparent when you start a session, but you actually have the entire user space of your Linux distribution available to you. Sure, you can execute your favorite shell commands as you would expect but the much larger implication is that you can install and run native Linux ELF64 binaries using your distribution’s software management system, such as apt-get in Ubuntu. And no, it is not some Hyper-V virtual machine sleight of hand at work here. You can learn more about WSL and its inner workings to better understand how the subsystem allows this to work but first let’s take WSL for a spin and start with some warm-up exercises

Your favorite shell commands with an added bonus

We will start with the classic “ls” command with a twist:

clip_image003

Not only can you work with the file system space that is created for WSL, but you can also directly access the Windows file system through mount points in “/mnt”. In fact, if you “echo $PATH”, you will notice that your Windows PATH is appended, which allows you to do things like:

clip_image005

Oh, did we mention you can call Windows executables from WSL? You can also invoke Linux binaries and capture the output from Windows. While you think about what that could mean for DevOps scenarios, try some more of your favorite shell commands, like grep, awk and sed. If you are a little rusty with your shell commands, check out Jessica Deen’s, “15 Ubuntu Linux Commands Everyone Should Know.” You will be pleasantly surprised by the depth of the filesystem functionality including some of the more advanced features such as Unix sockets that are slated for the next major update for Windows 10 Spring Creators Update (RS4) in Spring 2018. Although working with Windows files from WSL is supported there is one caveat – do not change the files in the WSL filesystem space from Windows.

Let’s install something

Possibly the most compelling aspect of WSL is the ability to install native Linux applications directly with the distribution’s software management system. If you are using Ubuntu, you can simply,

sudo apt-get install {application}

clip_image007

And with the interoperability with Windows, you can access the service from Windows:

clip_image009

Note: If you have IIS running on port 80, you can change the port for the nginx default site (/etc/nginx/sites-enabled/default).

You no longer need to look for the Windows port of the application or try to build your own from source with Cygwin and then repeat the process with each update of the application. You also don’t need to worry about any “quirks” in the way those applications behave from the native Linux version or struggle with compatibility issues with add-on libraries like Ruby gems.

Seamless interaction with Windows

Something you will notice fairly quickly is how seamless the user experience is with Windows. Not only can you view the Windows file system from WSL but services in WSL can be accessed from Windows. The interoperability allows for a fluid way to develop in Windows with Visual Studio with code that is designed to interact with Linux-first type platforms like Node.js and Ruby on Rails running in WSL. Visual Studio Code, for instance, capitalizes on that interoperability with the option of setting WSL as the default integrated terminal. Press Ctrl+Shift+P then enter “select default shell” to access the Terminal default shell configuration and select “WSL Bash“.

clip_image011

Developers can drop into a terminal to execute Linux environment tasks for the project such as running a GCC compilation process without leaving the IDE. In Visual Studio 2017, the Linux Development with C++ workload can be configured to target your local WSL installation as the Linux environment.

Want to experiment with your ASP.NET MVC application designed for Azure Redis Cache against a local Redis instance in WSL before deploying to Azure? The interoperability with WSL can facilitate that. Modify the appSettings entry in Web.config to point to your local WSL Redis instance:

clip_image012

clip_image013

clip_image015

All made possible without a resource-heavy VM on your development PC which may or may not have the horsepower to do so effectively. The interoperability between WSL and Windows continues to be enhanced and we will see significant new features in upcoming Windows updates.

Coming soon

Speaking of new features, we should be seeing many improvements and highly anticipated new features in the Spring 2018 with the Windows 10 Spring Creators Update (RS4). Some of the highlights of the update include:

There is continued excitement for WSL as new features have been added in every Window 10 release since the Anniversary Update (1607). We expect there to be additional features and improvements in Windows 10 (RS5) in late 2018.

Why WSL deserves a spot in your development toolbox

There are many tool options natively on Windows that are available to accomplish the tasks we’ve covered but the real compelling aspect of WSL is the user experience. It is simply seamless when you need to work in or with a Linux environment. WSL is a remarkable product that gives you nearly the functionality of a full blown VM without the momentum crushing hassle of spinning one up. It also gives you an opportunity to streamline the number of disparate utilities you have had to juggle in the past. As modern applications integrate more cross-platform tools and services such as .NET Core, microservices and containers, developers and DevOps professionals will find WSL to be invaluable for their productivity.

Tell us how you are using WSL in the comments section below.


Special thanks to Tara Raj (@tara_msft), Rich Turner (@richturn_ms), and Jessica Deen (@jldeen). Discover the latest WSL features at the Windows Command Line Tools for Developers blog, https://blogs.msdn.microsoft.com/commandline/


Premier Support for Developers provides strategic technology guidance, critical support coverage, and a range of essential services to help teams optimize development lifecycles and improve software quality.  Contact your Application Development Manager (ADM) or email us to learn more about what we can do for you.

Premier Developer
Premier Developer

Premier Support for Developers

Follow Premier   

1 comment

  • Alan Sargent
    Alan Sargent

    “Why Developers Shouldn’t Install WSL Today” (assuming your machine is not so direly underpowered that it can’t afford the miniscule requirements of Linux):
    1/ you’ll learn the basic Linux skills that obviate the ‘seamless experience’ described here – like mounting your Windows drives under /mnt yourself, and using SSH through a terminal emulator like in the real world,2/ more importantly you’ll learn the basic Linux skills full stop rather than being in Microsoft box and not knowing where the box ends,3/ you’ll be able to use real Linux, any Linux, different Linuxes, complete Linux – not just a headless Linux, not a clone of Linux, the Linux that powers the world,4/ you’ll learn about virtualisation tools – they are not hard, they are fun, and powerful, (Windows 10 in a VM on Linux drags it down, Linux in a VM on Windows doesn’t)5/ when you one day go and use Linux outside Windows 10 you’ll already have the skills because you wont have been wearing training wheels with your hand held.

Leave a comment