Start Here: Windows Subsystem for Linux

Gamze Yılan
4 min readOct 11, 2020

I heard a rumor: dualboots and virtual machines are not the only options to use both Linux and Windows on the same machine anymore!

Are you still using your computer on a dualboot, or worse, a tripleboot? Virtual machines don’t really do the job now, do they? Don’t you wish that you could use that app or tool you love on Linux, on Windows as well? And I bet you are sick and tired of having to close everything & restart your machine in order to switch between operating systems, huh? If so, Windows Subsystem for Linux is just for you!

  1. What is WSL?

Windows Subsystem for Linux (WSL) is a compability layer, or an interface that allows a foreign system such as Linux distributions (Ubuntu, Kali, Manjaro…) to run on a host system such as Windows. You can think of this as a translator between two systems. The WSL will let you run a GNU/Linux environment directly on Windows, without the need of dualboot or a virtual machine. This can come in handy especially when you need a Linux app, tool or utility to run on Windows.

2. WSL 1 vs WSL 2

You will find that there are two architectures available, WSL 1 and WSL 2. While serving the same purpose, WSL 2 will make reading and writing files significantly faster and ensure you can run some programs you couldn’t run before (like Docker) as well.

WSL 1 will basically act like a translator; instead of having you use a real Linux kernel, it will simply turn the Linux kernel calls into Windows kernel calls and vice versa. WSL 2, on the other hand, will work on a real Linux kernel built and maintained by Microsoft. This difference not only makes the process about 20 times faster, but also allows for a real Linux experience, giving you the full system call compability.

You may, however, prefer to change between WSL 1 and WSL 2. You can change the default version, or you can make a specific Linux distribution you installed previously use a different version than the default.

In order to change the default version to WSL1 or WSL2 you will have to follow the steps below;

  • On your Windows OS, right click on the start menu and select “Windows PowerShell (Admin)”
  • Allow the app to make changes to your device by clicking “Yes” on the pop up window
  • For WSL 1, copy and paste the following command line on the PowerShell and hit enter

wsl — set-default-version 1

OR

  • For For WSL 2, copy and paste the following command line on the PowerShell and hit enter

wsl — set-default-version 2

In order to set a specific, pre-installed Linux distribution to WSL1 or WSL2 you need to follow the steps below;

  • On your Windows OS, right click on the start menu and select “Windows PowerShell (Admin)”
  • Allow the app to make changes to your device by clicking “Yes” on the pop up window
  • Copy and paste the command below, hit enter, and decide which distribution you would like to change.

wsl — list — verbose

  • Copy and paste the command below after you edit it based on your needs, and then hit enter to run

wsl — set-version <distribution name we have picked above><version numer: type 1 for WSL1 and 2 for WSL2>

Example: wsl — set-version Ubuntu 1

3. How to get it:

  • Go to the start bar on Windows 10 OS (Make sure you are using the latest version)
  • Find the “Control Panel”
  • Go to “Programs”
  • Click “Turn Windows features on or off”
  • For WSL 1 Tick “Windows subsystem for Linux” alone or for WSL 2 tick both that and “Virtual Machine Platform”, then click OK
  • Reboot your PC once an installation is completed
  • Go to “Microsoft Store” and type in the name of the Linux distribution you would like to use, click “Install”
  • Type the name of the distribution on the start menu and double click to launch

After you launch the OS of your preference, the shell will require you to type in a username as well as a password for the sudo user (admin). From there on you can use this shell as the command prompt of your new OS. Overall the language you will have to use will be, since this is Linux, Bash. Therefore you can use most commands found in Bash right away.

In order to not run into any issues later, I suggest you write the command line below and update all repositories before anything else:

sudo apt-get update

Keep in mind that running any sudo command will ask you for the sudo(admin) password.

4. But what about the UI?

If you need to run graphical Linux apps or feel that you need a UI, you can download GWSL through the link below;

4. WSL for Visual Studio Code

You will find that running some programs on your Linux through WSL might require a few extra steps. Visual Studio Code is one of them.

In order to work with Visual Studio code through WSL, you need to first make sure that VS Code is installed on your Windows. Then, you can simply open VS Code through your WSL Linux terminal by typing “code .”. Once VS Code is loaded, the program is going to suggest you to install an extension named “Remote -WSL”.

After that, if you use your Linux terminal to run the VS Code once again, you will now be working inside your Linux rather than Windows.

Notice: Make sure that you save the code you write through VS Code according to the Linux file structure in order to have it run properly. You can do so by simply following the format below;

fileName.fileType

Examples: file1.py, file2.php

--

--