Hello Newbies in Tech! Try This Powerful Tool by Microsoft to use Linux Effortlessly with Windows OS
Tags: codenewbie, webdev, beginners, wsl
Published: 2020-02-04 09:47:54


*Originally published on my blogging site [ajeet.dev](https://ajeet.dev/windows-subsystem-for-linux/)*

---
**I am a newbie in tech. I have been using Linux and Windows side by side for quite some time now. This blog post is based on my personal experience. Feedback Welcome. Would really appreciate your time 🙏**

---
I have been documenting my tech journey on my blogging site [ajeet.dev](https://ajeet.dev/) . It helps me organize my thoughts and adds value to my learning process. 
In my earlier blog post [Linux Vs Windows - Why Linux Is Better for Programming & Web Dev](https://ajeet.dev/linux-vs-windows-os/), I quickly compared some key features of both the Linux and Windows OS based on my experience. I found Linux Operating System quite developer friendly and the community is huge.  So, I switched to Linux (uninstalled Windows OS) to learn coding and web development. Being a Windows user and a newbie in tech, I started noticing some difficulties after I switched to Linux. I have documented my experience in this post [Hello Newbies in Tech! Switching From Windows to Linux? Read This First](https://ajeet.dev/switching-from-windows-to-linux/).

In this post, I will explain how to get started with a Linux distro on Windows machine **without actually installing any Virtual Machine software**. For this, we will install a tool called [Windows Subsystem for Linux (WSL)]( https://ajeet.dev/windows-subsystem-for-linux/). Installing this will be almost similar to installing a software on Windows (with a little extra effort).
There are several ways to use Linux but why did I install this tool in the first place?  I wrote about this in my [blog post](https://ajeet.dev/switching-from-windows-to-linux/)

*Note: This blog post is written purely for beginners who want to get into the programming or web development. 

##💻 Windows Subsystem for Linux (WSL)
Windows Subsystem for Linux (WSL) is a handy and fast tool [announced by Microsoft](https://blogs.windows.com/windowsdeveloper/2016/03/30/run-bash-on-ubuntu-on-windows/ "WSL announced by Microsoft") to get a full GNU/Linux system inside of Windows. According to Windows,

> With WSL, we can run a GNU/Linux environment natively on a Windows machine without using any Virtual Machine

![Windows Loves Linux](https://dev-to-uploads.s3.amazonaws.com/i/jntbag7dpo5xzpa4sib6.png)

Running and using a Linux distro on Windows will be as easy as using a software on Windows.

## WSL 1 Vs WSL 2 - Two Versions of WSL
There are two versions of WSL - WSL 1 and WSL 2. The former was the first version and WSL 2 is the newer version of the architecture. In the newer version, the Linux distros interact with Windows in a different way. To enable new features in WSL 2, the architecture uses [virtualization technology](https://www.redhat.com/en/topics/virtualization/what-is-virtualization "virtualization technology")and a [Linux kernel](https://www.redhat.com/en/topics/linux/what-is-the-linux-kernel "Linux kernel"). To enable virtualization, it uses [Hyper-V architecture](https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture "Hyper-V architecture").

## Advantages of WSL 2

WSL 2 is faster than its previous version. The two main advantages of using WSL 2 are:

1.  [Faster system file performance speed](https://docs.microsoft.com/en-us/windows/wsl/wsl2-about#increased-file-io-performance "Faster system file performance speed")
2.  [Full System Call Compatibility](https://docs.microsoft.com/en-us/windows/wsl/wsl2-about#full-system-call-compatibility "Full System Call Compatibility")

According to [Microsoft](https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq#what-will-happen-to-wsl-1-will-it-be-abandoned "Microsoft statement"),

> *Adding WSL 2 as a new architecture presents a better platform for the WSL team to deliver features that make WSL an amazing way to run a Linux environment in Windows*

Please note that the speed will also depend on which app a user is running, but operations such as `git clone`, `npm install`, `apt update`, and `apt upgrade` will be faster in WSL 2. Overall, the newest version is said to be 2-5x faster.

It is worth mentioning that [WSL 1 won't be abandoned.](https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq#what-will-happen-to-wsl-1-will-it-be-abandoned "what will happen to WSL 1")


## Important Changes in WSL 2

There are two important changes in the current version.

-   In WSL 1, you need to put the files, you wish to access with Linux applications, in the C Drive of Windows. But in WSL 2, the files must be kept inside of Linux root system to reap the benefit of file performance.
-   As WSL 2 runs on a virtual machine ( no additional software need though), to access Linux network applications from Windows machine you need to use the IP address of that virtual machine. Similarly, to access Windows networking applications from Linux distro, you need to use the IP address of that Windows host. [More here](https://devblogs.microsoft.com/commandline/wsl-2-is-now-available-in-windows-insiders/).

[Here is the list of other changes in WSL 2](https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes "User Experience Changes Between WSL 1 and WSL 2"). You can also go through [this article](https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq "this article") to read more about WSL 2.

## ⏳ How to install the Windows Subsystem for Linux

Let's get into the real thing now. Here is a step by step guide to install WSL.

1.  Prerequisites
2.  Enable WSL 1
3.  Install a Linux distribution
4.  Complete initialization of your distro
5.  Enable WSL 2
6.  Set WSL 2 as your default architecture
7.  WSL Version Check

Let's get started.

## **Step 1: Prerequisites**

The **Windows OS build 18917 or higher is required**.  To check Windows build number, open Windows PowerShell as Administrator. To open it, press CNTRL + X buttons simultaneously using your keyboard and then click on “*Windows PowerShell (Admin)*”. Click *Yes* when prompted by User Account Control. Run the following command in PowerShell. This will give you the OS build number.

`systeminfo | Select-String "^OS Name","^OS Version"`

![ 1Command to find Windows OS Build Number](https://dev-to-uploads.s3.amazonaws.com/i/5vi9vbu7picsi4xn030f.png)

If the build is not 18917 or higher, you need to join the [Windows Insider Program](https://insider.windows.com/en-us/ "Windows Insider Program") and select the '**Slow**' ring update type.

Caution: Before moving ahead, I strongly encourage beginners to read about [Microsoft Insider Program](https://insider.windows.com/en-us/how-to-overview/ "Microsoft Insider Program")*.* This talks about different types of Windows updates. Focus on the update type **Slow**. Once you have understood the risk, please proceed.

Open **Settings** > **Update and Security**. Look for *Windows Insider Program* and register your account.  Once registered and enabled, you will see 3 options for **Insider Settings**. Select **Slow (Recommended)**.

Now, update your Windows. Open **Settings** > **Update and Security** > **Windows Update**. Restart computer if asked. Check the build number again using the PowerShell command. This will fulfill the requirement to go ahead.

##  **Step 2: Enable WSL 1**

Open PowerShell as Administrator. Run the following commands one by one

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


```shell
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
```


Running the above commands will install Virtual Machine Platform and Windows Subsystem for Linux. Restart your computer. To confirm if [WSL is enabled](https://docs.microsoft.com/en-us/windows/wsl/troubleshooting#confirm-wsl-is-enabled "Confirm WSL is enabled"), run this command in PowerShell as Administrator.

```shell
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
```


If you get the similar output as shown in the image below, you are good to go.

![ 2Windows Command to Check WSL](https://dev-to-uploads.s3.amazonaws.com/i/kyjsqamqmg5pyf12zzhx.png)

##  **Step 3: Install a Linux distribution**

Now you can install your preferred distro(s), I recommend installing a distro from the Microsoft Store. In this article, I will install [Ubuntu](https://www.microsoft.com/store/p/ubuntu/9nblggh4msv6). Open Store and Search for Ubuntu. Always choose the [LTS](https://wiki.ubuntu.com/LTS "LTS") version. LTS means Long Term Support which receives five years of support without any charge. Click on the LTS version.

![ 3Search a distro using MS Store dashboard](https://dev-to-uploads.s3.amazonaws.com/i/028rfanmgol1o5rmvzrk.png)

A new page will open. Select "Get" and the distro will start downloading, and then it will be installed. If you want to install a different distro, please use this official [Microsoft guide](https://docs.microsoft.com/en-us/windows/wsl/install-win10#windows-10-fall-creators-update-and-later-install-from-the-microsoft-store "Microsoft guide to install a Linux distro").

##  **Step 4: Complete initialization of your distro**

Once you have downloaded and installed a Linux distro, you need to complete initialization of this new distro. This is similar to what we do (such as set your username, password, etc.) during installing a Windows OS. Click on "Launch" button as shown in the image below.

![ 4Launch a distro using MS Store dashboard](https://dev-to-uploads.s3.amazonaws.com/i/ka5rzr1avefn89lifw05.png)

A pop screen will appear. You will set username and password there. You can also follow [this step by step guide to initialize a newly installed distro.](https://docs.microsoft.com/en-us/windows/wsl/initialize-distro "step by step guide to initialize a newly installed distro")

Moving ahead. Run `wsl -l` in PowerShell to check your installed distro. You will see the name of your distro.

![ 5Find distro using wsl - l command](https://dev-to-uploads.s3.amazonaws.com/i/cpa7np4pjwybcsyt7p1v.png)

Here I have installed Ubuntu-18.04 and this is the default distro. To check which version of WSL is installed, run `wsl -l -v` . It will display a '1' under the 'version' column.

##  **Step 5: Enable WSL 2**

In this step, we will set our distro Ubuntu to be backed by the newer version of WSL architecture - WSL 2. For this, you need to find your distro name. You can find this by running `wsl -l` command. It is Ubuntu-18.04 in my case. To enable WSL2, enter the command:

`wsl --set-version Ubuntu-18.04 2`

You will see "*Conversion in progress, this may take a few minutes...."*. Wait for sometime.

In the above command, you can always replace the word `Ubuntu-18.04` with the name of your installed distro. The 2 in the command means we are going to change architecture to WSL 2.

You can always go back to WSL 1 by running the above command and replace the '2' with a '1'.  
Note: In my case, during conversion from WSL 1 to 2, I got a error, which says, "*Exporting the distribution failed. bsdtar: Write error".* Here is the screenshot.

![ 6Conversion Error from WSL 1 to 2](https://dev-to-uploads.s3.amazonaws.com/i/ag32chvbyx27c9v04nmg.png)

Many people have found the same [issue while converting version 1 to 2](https://github.com/microsoft/WSL/issues/4394 "issue while conversion 1 to 2"). To fix this issue, "[Turn Off Windows Real Time Protection](https://support.microsoft.com/en-us/help/4027187/windows-10-turn-off-antivirus-protection-windows-security "How to turn Off Windows Real Time Protection")". Run the conversion command again. This worked for me.

Check the [GitHub thread](https://github.com/microsoft/WSL/issues/4394 "GitHub thread") to find the other fixes if the above did not work for you. Please note that you may need to run the conversion command twice if the conversion throws error during the process.

Do not forget to "Turn On Windows Real Time Protection" once the conversion is done.

##  **Step 6: How to set WSL 2 as your default architecture**

If you wish to always use WSL 2, make sure you make this architecture as the default. Meaning whenever you will install any distro from Microsoft Store, the newer version WSL 2 will be installed. Run this command in PowerShell as Admin.

`wsl --set-default-version 2`

##  **Step 7: Check which version of WSL is Installed**

To check which version of WSL is installed, run `wsl -l -v` . It will now display a '2' under the 'version' column.

![ 7Ubuntu distro with WSL 2 Running](https://dev-to-uploads.s3.amazonaws.com/i/3jswiibhkvpmrcy6zfu3.png)

## **⚒️ Troubleshooting**

Microsoft has a [dedicated page](https://docs.microsoft.com/en-us/windows/wsl/troubleshooting "dedicated page for WSL issues") for the WSL related errors and fixes. For WSL 2 related issues, click [here](https://docs.microsoft.com/en-us/windows/wsl/wsl2-install#troubleshooting "WSL 2 issues").

## **🏃 Running WSL**

Now that we have installed Windows Subsystem for Linux, you need to update Ubuntu. From the Windows Start Menu, find Ubuntu 18.04 LTS (that is what we have installed). Run the program as Admin.

![ 8Run Ubuntu from Start Menu](https://dev-to-uploads.s3.amazonaws.com/i/9nh1ivjvl5mss26a2pob.png)

You will see a pop up command shell. To update the local database of available packages and upgrade the installed packages of Ubuntu, run this command:

`sudo apt update && sudo apt upgrade`

More about the above command is explained [here](https://explainshell.com/explain?cmd=apt-get+update+%26%26+apt-get+upgrade "ubuntu update command").

You would need to enter your password that you set during the initialization of your distro. During this process, it will ask your permission to download and install updates. Type Y.

![ 9Give permission to ubuntu to install update](https://dev-to-uploads.s3.amazonaws.com/i/9dngli9160ohy4y1ais8.png)

Once the update finishes, the set up is complete.

##  **💡 What's Next**

Once you are comfortable with the WSL installation, please read my next post [A Beginner's Guide To Use Windows Subsystem For Linux](https://ajeet.dev/how-to-use-windows-subsystem-for-linux/). My next post will be about how to use Microsoft VS Code and Git inside WSL. Meanwhile, keep Googleing 🤓



---

**Don't forget to subscribe to my weekly [Newsletter](https://ajeet.dev/subscribe/) 📧**

---



---

*Credits 🙏 : * 
- [Official Microsoft Docs on WSL](https://docs.microsoft.com/en-us/windows/wsl/about "Official Microsoft Docs on WSL")
- Windows and Linux logos taken from [SimpleIcons](http://simpleicons.org)
- Emojis taken from [Emojipedia](https://emojipedia.org/)
- Cover image built with [BlogCover](https://blogcover.now.sh/)