How to Set up your Linux Development Environment on Windows

Nitin Madhavan
5 min readFeb 10, 2021
Ubuntu/Vim and VSCode on Windows

Ever since I can remember, I have always had my computers and laptops configured in Dual Boot mode to shift between Windows and Linux. In the early days, the Linux partition was more for fun and experiments, while I would do my development using Visual Basic, Delphi, C#, etc. on Windows. However, in the early 2010s, I found myself using Linux more and more for development, and when I changed over to Python full-time, Linux became my primary development environment. I did use Anaconda sometimes when I needed to work on Windows. But it was never a smooth experience, and I would scoot back to Linux as soon as I could.

However, minor irritants of having a dual-boot system remained. There would be times when I would need to use a specific software which was only available on Windows, or quickly edit a Microsoft Office document without worrying about messing up the original formatting. I did try Virtual Machines for some time, but their resource requirements made them impractical on my mid-range laptops. So I continued with the dual-boot solution.

COVID-19 shook up the status quo. Work from Home led to the requirement of frequent VCs. Various organisations used different software, and I found myself on many an occasion unable to participate as my Linux installation would not work smoothly with the hardware. On the other hand, using Windows made it difficult to demonstrate development done on the Linux environment. Shifting between the two was becoming a pain.

So I decided to give the Windows Subsystem for Linux or WSL a go and see if it met my needs of having a Linux Dev Environment on my Windows machine. I was not very hopeful about the experiment. But I must say that Microsoft has done an incredible job, and I have now been on WSL for over 9 months. In fact, a few months back, I even removed my Linux partition as I was no longer using it.

This blog post and a few follow-on posts are a tutorial based on my experience in building a Linux Dev Environment on Windows using WSL. I will cover the topic under the following heads.

  • A short introduction to WSL
  • Installing WSL2 and Linux on Windows
  • Use Docker Desktop to create a Development Environment.

Introduction to WSL

WSL lets you use the tools you want, in the environment you want, on the hardware you want.

As the Microsoft documentation says — In the past, most dev professionals would have told you to stick with macOS or Linux because the most common development tools, languages, and frameworks were easy to install and work with. All that has changed with the Windows Subsystem for Linux (WSL). WSL lets you run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified and fully integrated with your Windows file system and favourite tools like Visual Studio Code.

WSL comes in two versions — WSL and WSL2. The original release of WSL was in 2016. WSL2, which was recently released, has a significantly different architecture and provides complete system call compatibility and much better performance. However, it requires Windows 10 version 1903 or higher, with Build 18362 or higher, for x64 systems. Here is a slightly more detailed, yet simple, look at the difference between them. I will be using WSL2 for this tutorial.

Install and Configure WSL2

Check you are using Windows 10 Version 1903 or higher, with Build 18362 or higher. You can check by pressing the Windows logo key + R and type winver in the box.

Open Powershell as Administrator and run the following commands.

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

Restart your system as it installs and updates to WSL2.

Download the WSL2 Linux Kernel for x64 machines and run the package.

Open Powershell and set WSL2 as default on your system.

wsl --set-default-version 2

We can now go ahead and install Linux. Here is a link to the Microsoft Documentation for WSL2 installation.

Install and Check Linux

Install your preferred Linux Distribution from the Microsoft Store. Once installed, open Powershell and run the following command.

wsl --list --verbose

You should see something similar to this.

You can also confirm that the version is 2 for WSL2.

Now that you have installed Linux, you can enter the Linux Shell by typing the following command in the Powershell / Command Prompt.

wsl

This will open the default Linux installation.

In case you have installed multiple distros, you will have to specify which one you want to open. You can also launch it from the Start Menu. Your new Linux system will start in a console window. The first time it may take a few minutes. The next time onwards, it will start within a second.

Accessing Files in the Linux Filesystem from Windows. You can access the Linux filesystem in the Windows file explorer using the following command in the Linux shell.

explorer.exe .

Do not forget to add the space followed by Dot. The file explorer allows you to copy and paste files between the Windows and Linux filesystems.

Some Useful Tools to Install

The next step is to install a few useful tools for developers. The first is Visual Studio Code. Install VSCode on your Windows machine and the Remote — WSL extension. To start using VSCode on Linux, type the following command in the Linux Shell.

code .

The VSCode should open in Windows for editing files on your Linux system. The first time, it may take some time to install the required libraries. The next time onwards, the startup will be quick.

Note: If any of the above commands from the Linux Shell do not work, you may try restarting the Linux shell by typing the following command in the Powershell

wsl --shutdown

Once it has shutdown, restart Linux either from the Start Menu or Powershell.

You can also consider installing Microsoft Terminal, which is a very cool terminal for windows.

Conclusion

You can now use the WSL Linux Shell like any Ubuntu Linux installation without a GUI and are now all set to use Windows as a Linux Development machine.

In the next blog, we will look at how I have configured my development environment for Machine Learning using Python. I will also cover Docker Desktop as I find many advantages in using it for my Dev environment.

Thanks for reading. Hope it is helpful. Let me know if you have any queries or face any problems in the comments section.

--

--