Home Audience Admin The Advantages of Using WSL for Developing Linux Applications on Windows...

The Advantages of Using WSL for Developing Linux Applications on Windows Systems

0

It is common to have cross-platform development of applications, since most developers do not have multiple machines. Today, it is quite simple to install a Linux development environment in a machine that has a Windows OS, thanks to the Windows Subsystem for Linux (WSL) feature offered by Microsoft.

Many Linux application developers have Windows OS machines and use remote Linux servers for work by connecting through SSH (like installing PuTTY software on Windows). These Linux servers/machines are generally shared among multiple developers for their development work. However, very often developers want their own machine instance and that is when a virtual machine (VM) is used.

On Windows OS based systems, there are VM solutions like VirtualBox or VMware, through which you can install any Linux distro (or any operating system for that matter) you like from an installer ISO. But many developers do not like this due to the performance (it’s very slow and heavy for the overall host system), compatibility issues, lack of tools and support.

Windows Subsystem for Linux (WSL)
Remote host connections or virtual machines were the only ways to develop Linux applications on Windows machines until Microsoft came up with WSL (Windows Subsystem for Linux) in 2016. WSL allows you to run Linux distributions on 64-bit Windows 10 (from version 1607) based systems. It only supported the Ubuntu Linux distribution initially, but now supports many other Linux distributions.

The distributions listed below are directly available in Microsoft Store:

  • Ubuntu 16.04 LTS / 18.04 LTS / 20.04 LTS
  • openSUSE Leap 15.1
  • SUSE Linux Enterprise Server 12 SP5 / 15 SP1
  • Kali Linux
  • Debian GNU/Linux
  • Fedora Remix for WSL
  • Pengwin
  • Pengwin Enterprise

Alpine WSL
(There are many other Linux distributions that are unofficially supported by WSL.)
For Linux application developers, WSL provides the Linux development environment — which comprises most of the command line tools, utilities and applications — directly on Windows without the overhead of a traditional virtual machine or dual-boot machine setup. This is a far better user experience than Cygwin, which was used for basic Linux development environments on the Windows OS.

Note: Microsoft released WSL2 in 2020, which is an improved version and faster than the first version. However, for simplicity we are considering the first version of WSL in this article.

The prerequisites for WSL are:

  • Windows 10 (version 1607 or above).
  • WSL only runs on 64-bit versions of Windows 10. The 32-bit version is not supported.

Installation
Here is an example of setting up a WSL environment using Ubuntu 18.0.4 LTS. There are two ways to do this — through Microsoft Store and through the PowerShell command line.

Microsoft Store: You can directly install the desired distro by searching for it (say, Ubuntu) in Microsoft Store. If Microsoft Store is not installed or not accessible, you can install it through the command line as mentioned next.

PowerShell: Open PowerShell as administrator and follow the steps given below.

1. The first step is to enable the Windows optional feature–WSL by executing the command given below:

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

It will ask for a computer restart.

2. Once the machine has restarted, the next step is to download Ubuntu-18.04 through the PowerShell command line (for a different version, kindly check https://docs.microsoft.com/en-us/windows/wsl/install-manual):

Invoke-WebRequest -Uri 
https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx –UseBasicParsing

3. Extract the downloaded distribution by executing the following commands:

Rename-Item -Path ~/Ubuntu.appx -NewName Ubuntu.zip
Expand-Archive ~/Ubuntu.zip ~/Ubuntu

4. To run the Linux distro (Ubuntu), change to the extracted directory and execute the binary:

cd Ubuntu
./ubuntu1804.exe

5. Once you run the distro name executable, it will start setting up the environment and ask for a new user name and password; after that you’re good to go.

Leveraging Microsoft development tools
As WSL is natively integrated with the Windows OS, developers can build and debug Linux applications with Windows tools like Visual Studio Code and Visual Studio. Visual Studio Code (https://code.visualstudio.com) is a free and powerful IDE, which has an extension that allows you to attach VSCode to WSL directly (refer to the document explaining this process at https://code.visualstudio.com/docs/remote/wsl). This helps developers to use the powers of the GUI IDE of Windows and command line of Linux simultaneously. There are many other extensions (code formatting, Git history, Docker, etc) in VSCode that give developers lots of flexibility.

WSL vs virtual machine software
Performance is always a concern for developers when they use VMs. Most benchmarks suggest that WSL performance is nearly as good as native Linux distributions. However, in some I/O tests bottlenecks were experienced while using WSL. The new version, WSL2, has improved upon this.

WSL has quite a few benefits over virtual machine software. These are:

  • It’s lighter than a virtual machine and consumes fewer resources (CPU, memory and storage).
  • Easy to setup.
  • Natively integrated with Windows OS and supported by Microsoft.
  • No third party VM software is required.
  • Fairly large community and good documentation available from Microsoft, which allows even developers who have never used Linux before to get started easily.
  • Speeds up the development process in case of cross-platform projects.
  • You can share Windows apps and Linux tools on the same set of files.
  • In general, almost near native Linux distro performance.
  • Very stable.
  • Cost-efficient (no licence fee).
  • Users can install the required packages (for example, if you are running the WSL Ubuntu image, you can install packages from the Ubuntu repository).
  • It offers distribution support. With Ubuntu LTS (long-term support) releases, users will have five years of security patches and updates.
  • Microsoft has been focusing on WSL development. WSL2 is a more mature version, which improves on the performance of the first version and also solves the issues the latter has.
    However, it is advisable to not use WSL in certain scenarios.
  • Do not use WSL when your application is GUI based, since it does not support GUI desktop applications. There are a few ways to configure WSL with a graphics subsystem to make some graphic applications work, but not all. So it is not recommended to run graphical applications on WSL.
  • WSL is not capable of running 32-bit binaries.
  • WSL is not suitable for applications which require specific Linux kernel services that are not implemented in WSL. You cannot run kernel modules like device drivers. However, future versions like WSL2 may support this.
  • WSL is not meant for production workloads.
  • It is suitable for the development of applications and not for desktop computers or production servers.
  • If you run/develop scientific applications that use GPUs, WSL requires Linux running on the bare metal. Again, this may be supported in future versions like WSL2.

Windows Subsystem for Linux (WSL) is a remarkable product and initiative from Microsoft that gives one the functionality of almost a full-blown VM without the hassle of spinning one up. WSL requires fewer resources (CPU, memory and storage) than a full virtual machine, and it also allows one to use Windows apps or tools along with Linux command line tools. Developers using Windows machines for building Linux applications find WSL has significant advantages over VMs.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version