loading...
Cover image for Hello Newbies in Tech! Try This Powerful Tool by Microsoft to use Linux Effortlessly with Windows OS

Hello Newbies in Tech! Try This Powerful Tool by Microsoft to use Linux Effortlessly with Windows OS

ajeet profile image Ajeet Updated on ・9 min read

Originally published on my blogging site ajeet.dev


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 . 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, 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,Β difficulties appeared immediately I switched to Linux. I have documented my experienceΒ in this postΒ Hello Newbies in Tech! Switching From Windows to Linux? Read This First.

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). 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

*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 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

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 technologyand a Linux kernel. To enable virtualization, it uses 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
  2. Full System Call Compatibility

According to Microsoft,

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.

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.

Here is the list of other changes in WSL 2. You can also go through 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

If the build is not 18917 or higher, you need to join the Windows Insider Program and select the 'Slow' ring update type.

Caution: Before moving ahead, I strongly encourage beginners to read about 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

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
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, run this command in PowerShell as Administrator.

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

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. Open Store and Search for Ubuntu. Always choose the 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

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.

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

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.

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

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

Many people have found the same issue while converting version 1 to 2. To fix this issue, "Turn Off Windows Real Time Protection". Run the conversion command again. This worked for me.

Check the 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

βš’οΈ Troubleshooting

Microsoft has a dedicated page for the WSL related errors and fixes. For WSL 2 related issues, click here.

πŸƒ 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

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.

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

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. 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 πŸ“§



*Credits πŸ™ : *

Posted on by:

Discussion

markdown guide
 

WSL2 is a massive mistake. It is build on Hyper-V, Microsoft's own hypervisor. It causes significant issues of many kinds - not least of which, that it's incompatible with VirtualBox, the hypervisor with which all other systems are compatible with.

Want to boot up a random Linux VM to try out things? Tough, you can't, Hyper-V is preventing Virtualbox from starting, and the Linux ISO won't boot in Hyper-V.

It's also been known to cause performance reductions for gaming, as well as triggering anti-cheat systems, and other such things.

I really tried to like Hyper-V for a while, but I had to give up on it. Still the best way to get most Linux utilities on Windows is Cygwin.

I wrote a bit about the setup I use for these things in dev.to/lietux/developing-like-a-pr...

 

Hi Janne,
It seems there are some workarounds about it. At docs.microsoft.com/en-us/windows/w... it says:
Some 3rd party applications cannot work when Hyper-V is in use, which means they will not be able to run when WSL 2 is enabled, such as VMware and VirtualBox. However, recently both VirtualBox and VMware have released versions that support Hyper-V and WSL2! You can learn more about VirtualBox's changes here and VMware's changes here.

 

It seems that page has been last updated about a year ago. The updates they refer to are things that I've already found to be broken.

6.0.0 from 2018 was supposed to fix VirtualBox with Hyper-V, it doesn't, it's really broken, and the entire VirtualBox community seems to know this as they typically suggest removing Hyper-V as the only solution to getting VirtualBox to work when your computer has Hyper-V enabled.

It seems you're only spreading old marketing propaganda from Microsoft without doing any actual research on it.

Yes, at some point they thought they could make it work, Windows implemented some APIs that were supposed to make it possible, but those have repeatedly broken and VirtualBox has not worked with Hyper-V enabled a little while after the initial successful beta tests.

Spreading old marketing propaganda? Easy please..

virtualbox.org/wiki/Changelog:
VirtualBox 6.1.4 (released February 19 2020)
This is a maintenance release. The following items were fixed and/or added:
Windows host: Restore the ability to run VMs through Hyper-V, at the expense of performance

Changelog is VirtualBox's own changelog, their own promise! so how come it is Microsoft's old propaganda? If VirtualBox is broken it is not Microsoft's responsibility but Oracle's.

If Microsoft breaks their APIs likely to intentionally break the compatibility with 3rd party virtualization software, how is that Oracle's fault?

And you linked to docs.microsoft.com/en-us/windows/w... a page last updated a year ago. A page which still made invalid claims about "recently both VirtualBox and VMware have released versions that support Hyper-V and WSL2" - out of date propaganda. The links on that page also link to VirtualBox 6.0 changelog - and all versions of VirtualBox 6.0 still fail to work under Hyper-V.

It's interesting that maybe VirtualBox has finally managed to fix the compatibility even without Microsoft's help using their proprietary intentionally broken APIs, but this might not be a long-lived solution and there is no sense in building any of your systems to depend now on Hyper-V since there are no guarantees it will not break again in the future.

Also this is far from the only issue with Hyper-V, though it was the most significant one to my work.

People are also reporting that the performance hit is severe, which is unlikely to be accidental.

Yeah, I can confirm the performance hit is severe. Had WSL2 setup and VirtualBox 6.1.6 I was able to start my Win7 VM, but since VirtualBox was forced to use Hyper-V the VM never made it past the Win7 start up animation after 10-15 minutes.

Ended up reverting back to WSL1 to get the performance back on my VMs.

Oh wow, that's worse than I thought .. I was just considering testing it out in the coming weeks for myself - thanks for saving me the effort!

 

If you have Windows Pro or Enterprise, then you can use the Hyper-V manager to set up your own VM's. There is even a "Quick Create" tool to download and install pre-configured disk images, Canonical Multipass is also a nice solution to any hiccup in installing Linux in Hyper-V.

 

Yes, I used Hyper-V manager to try and boot up some basic Linux images that boot in literally every other environment, they failed to launch a GUI and froze.

If it says "Canonical" it is basically guaranteed to only support Ubuntu.

 

It is kind of expected for 3rd party virtualization products not to work when Hyper-V is enabled, after all it's a type 1 hypervisor (native, like Xen or ESXi) and not a type 2 one (hosted, like VirtualBox or VMware Workstation).

When it's enabled the whole OS goes through it, so virtualization extensions aren't exposed and since they're required for some of not all type 2 virtualization offerings they won't work. Nested virtualization can be tricky, but I think there are some solutions out there that implement it (either by exposing virtualization extensions or by virtualizing without hardware assistance (with the performance penalty it entails)).

However, as it was stated before, both VMware Workstation and VirtualBox can now work when Hyper-V is enabled and I'm sure their implementation will continue to improve (at least VMware's being a commercial product and all).

As for WSL2, I find it useful, a great improvement from what SUA used to be and a step into the right direction in regards to WSL (it has to be easier to maintain for sure). I'm still using MSYS2 when it comes to Windows, but I'll certainly give WSL2 a try soon. I hope they keep working on it.

 

It is expected for them to have issues because of the way it's implemented. Which makes the way it's been implemented bad for everyone, and the fact that e.g. Docker's default Windows installation depends on it pretty distasteful.

No, VirtualBox does not work in an acceptable way. I don't care about VMWare because it's not widespread, affordable, and manageable with vagrant and other such tools, so it may or may not work but it doesn't change my ability to use Hyper-V at all. No it will not keep getting better when Microsoft is actively working against that goal.

This is basically Microsoft trying to kill all other virtualization options in favor of Hyper-V - in a sensible world this should land Microsoft in yet another antitrust lawsuit.

 

Hi Janne,
Bookmarked you post. I will definitely check out the issues you have mentioned.
Windows WSL team is amazing btw πŸ™‚. Hope they fix the issues you mentioned

 

Well, the issue with WSL is that it's built on Hyper-V - the WSL team has nothing to do with Hyper-V's issues and the only thing they can do to help with that is to choose to not use Hyper-V.

 

I was such a huge fan of WSL that I even bought a distro from the Windows Store. I came to Windows from years of Linux/BSD, and I wanted to bridge the gap. I even managed to get Arch on WSL.

Honestly, it has been a long time since I've fired up anything but PowerShell Core in my Windows Terminal. At this point, unless I need to reach for jupyter notebooks again, I'm not sure what I will use WSL for, and it kind of makes me sad.

It's inspiring that you can have Linux in your Windows environment, and you can run PowerShell Core on Linux. We live in an exciting time!

 

Hi Jesse,

I did not know that one can purchase any distro and that too optimized for WSL. πŸ˜€ Thanks for the info.

And honestly I think, people using MacOs or a Linux will rarely switch to Windows. I think never ever. Windows is for newbies like me 😁 . I use Excel, and a data visualization software Tableau, that's why I need to use Windows.

And I am sure you have heard of Kaggle Kernels and Google Colabs for Jupyter notebooks. I have used in the past but for basic exploratory data analysis. They look promising.

 

Ooo, I'm actually fairly new to python and data science, so those are brand new tools for me to check out. Thanks!

Never say never! I made the switch. 😊

Mac users, though … they're probably the toughest sell of all.

Definitely check Kaggle and Google ones. They are extremely useful.

Mac users, though … they're probably the toughest sell of all.

Couldn't agree more 😁

I use linux for programming but dual boot windows for games, linux is just not as good in terms of gaming performance

 

Great article. I also think it's worth mentioning the new Microsoft Terminal project. Works well with WSL.

I'd also like to see some information based around connecting an IDE (like IntelliJ or CLion) to WSL for native code compilation.

Other than that, thanks again for taking the time to write this one up! Great for anyone starting.

 

Thank you Jef for your comment πŸ™‚
And yes, the new MS terminal looks cool. I cab create new tabs which is great. I used it a couple of months ago but it lacked the copy paste feature. I just hope they add this functionality.

 

You don't have to install specified version package from the store, the standard one "Ubuntu" (without anything more) is better than version packages as it downloads the latest LTS version of Ubuntu and allows upgrades to future releases unlike the others.

 

Oh i did not know that. Thank you Kamil

 

why we need to run the Ubuntu with administrative privilege ?

 

Hi Filip :)

I trust the Ubuntu app (downloaded from app store), that's why I run it as admin. As far as I remember, I could not recall any step that required admin privileges during the installation.

 

Hi again Ajeet! Great post, you're doing more easy mix the Windows world and Linux world, greetings

 

Thank you 😊 Jose. You are very kind

 

great read, one question though. how do you make those cool terminal snapshots ? is it a theme ?

 

Hey, Thanks :)

I use this website.

carbon.now.sh/

It is open source: github.com/carbon-app/carbon

 

Hello @ajeet nice post, do u know if wsl2 supports docker volume and electron js? i droped wsl because of this conflicts on wsl1 and didnt had time to test on wsl2

 

Hi Saulo,

I will have to check about docker.
For electron, plz check this guide

gist.github.com/wsargent/072319c21...