Linux OS is widely known as a productivity tool, especially for developers. It gives more flexibility and power to complete various tasks during development. On the other hand, Microsoft Windows holds the first place as the OS used for desktops because of its easiness, simplicity, and convenience. Based on StatCounter’s Desktop Operating System Market Share Worldwide data, 75.34% of desktop users in December 2022 used Microsoft Windows.
If you are looking for the convenience of using Microsoft Windows combined with the productivity of Linux, then Windows Subsystem for Linux (WSL) might be the solution for you.
In 2016, Microsoft released WSL as a new feature, targeting developers to increase flexibility and productivity. WSL allows Windows users to run popular Linux distributions with a few simple steps and without third-party applications so that Windows and Linux can be used together.
Let’s dive into this feature and see how we can use it to increase our productivity as developers.
How to Install WSL
To start exploring WSL, we need to follow a few simple steps. Firstly, we must ensure we meet the prerequisites by using Windows 10 version 2004 or higher (Build 19041 and higher) or Windows 11.
Next, let’s follow these steps.
- Open PowerShell or Windows Command Prompt in administrator mode.
- Run the following command:
- wsl –install
- Restart the computer.
That is all. With only one command, we can start exploring using WSL. This command automatically sets up the required package and comes with the Ubuntu distro. We can choose other distros by adding -d flag followed by our preferred distro. Many distro options are available such as Ubuntu, Debian, Alpine Linux, or even Kali Linux
What We Can Do with Linux
Here are some things that we can do with Linux as a developer:
Utilize Linux Bash for Daily Development
Linux bash is a powerful tool.
At first, Linux bash/CLI can be intimidating since there is no visual menu or graphical user interface (GUI) on CLI, and we must type all of the commands we want to run. However, it is a very versatile tool for developers. With bash, we can create our script and give our OS a list of instructions. It allows us to automate some tasks and delegate them to our script.
Some tasks include checking our application version at the start-up, creating automated notifications to monitor service health, or creating a shortcut command to access our remote server. There are endless possibilities to create, and there are a lot of developers who share their scripts to automate some tasks.
However, we must ensure we understand the script if we want to try running other developers’ scripts on our device.
Install Linux Bash Application
One key benefit when using WSL is the ability to use Linux bash to use package installer commands like apt. We can type “apt install” followed by our application name, which will be installed and ready to use. We do not need to search for the installer, find the proper type for our machine architecture, download the installer, and install it. We can just run the command to accomplish that task.
Simply put, it reduces the time needed to install something. If you weren’t aware of this powerful command, many resources are available online to help you.
The WSL team has updated WSL to WSL 2 by default. It comes with an entire Linux kernel with complete system call compatibility, giving developers more options for running Linux applications. Docker is one example of an application that utilizes this benefit. Besides running Linux commands on WSL, we can run other Windows tools, such as Notepad from WSL. So, we can edit our Linux file with Notepad or, even better, with Visual Studio Code.
Replicate the Server for Smoother Integration
Besides writing code as a developer, we must test and ensure our code runs as expected before sending it to our tester. Testing code can be tricky, and several factors can affect our code: dependency version, database schema version, and OS, to name a few.
Most servers are running Linux for both testing and production. When we use WSL, we can replicate our server environment to our local machine in terms of OS and other applications based on our project needs. If we already use Docker to replicate the environment, the good news is that Docker runs faster on WSL. In fact, WSL has become the recommended option when using Docker on Windows. With this feature, we can minimize development environment difference factors and increase our confidence that our code is working.
WSL VS. VM
So, is WSL simply a form of VM?
Let’s check out the following benefits of using WSL rather than VM.
VM Management
WSL utilizes Hyper-V virtualization technology that comes with Windows 10 and newer. Compared with other 3rd party VM, WSL has a lightweight utility VM that starts and stops automatically. WSL will detect if we do not have any open file handles for Windows processes, and these will automatically shut down, which can save our resources.
Resource Allocation
Third-party VM usually uses “full virtualization,” which creates a special environment for our VM. It blocks access to certain hardware components and allocates it for the VM. WSL does not block our resources from other uses. WSL will automatically manage resource usage depending on our WSL workload. So, we do not have to precisely define how many CPU cores or RAM to allocate for our WSL. However, we can play around with this configuration if required.
File System Integration
Another WSL feature is that we do not need to integrate or share our file system on those OS since WSL already does it for us. It is quite easy to access and share our files on both OS. We can even explore our WSL file system on our Windows File Explorer. From a Linux perspective, WSL will automatically mount our Windows partition into the Linux file system without adding more script or editing some files.
Conclusion
WSL could be a solution to getting more flexibility when using Windows as your primary OS for development. It gives you the benefits of Windows and the power of Linux that developers can use to increase productivity.
Reference: https://gs.statcounter.com/os-market-share/desktop/worldwide
Author: Zainul Saifulah Aziz, Software Engineer Junior Programmer