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, 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.
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
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:
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.
- Prerequisites
- Enable WSL 1
- Install a Linux distribution
- Complete initialization of your distro
- Enable WSL 2
- Set WSL 2 as your default architecture
- 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"
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.
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.
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.
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.
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.
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.
⚒️ 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.
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.
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 🙏 : *
- Official Microsoft Docs on WSL
- Windows and Linux logos taken from SimpleIcons
- Emojis taken from Emojipedia
- Cover image built with BlogCover
Top comments (41)
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...
This comment is totally alarmist, i've used hyper-v with a few linux ISO and had no problem booting, you just have to read some instructions carefully. e.g. Disable secure boot, Gen 1 vs Gen 2, etc...
Yeah, so because a year later you tested a few ISOs and YOU ran into no issues nobody could ever have had any issues with it?
You just have to read some documentation that is likely nowhere to be found by mere mortals. Gotcha.
Even when it "works" Hyper-V is terribly slow compared to VMware Workstation or VirtualBox for e.g. Docker builds.
Ended up in this thread on a related search on DB speed comparisons under Hyper-V and WSL2. And found it a bit misleading.
The Linux ISO-s have been working on Hyper-V since 2014 (Debian. Redhat. I've run Oracle DB on Oracle Linux on Hyper-V), the fact that you have to turn off secure boot is also well documented, and pretty much the first result in the google search for linux iso not booting on hyper-v gen 2 gives in a preview a solution on how to fix it (by turning off secure boot). Btw. the MacBook Pro has a nasty feature where the CPU has some virtualisation bits left in "UNDEFINED" state, and debugging that was definitely a challenge (really nice hardware though).
As for performance, I can't complain, it's performant enough to boot up a complete dev env with several clusters of elastic, rabbit etc. and the throughput numbers (even for rabbit running in java VM-s inside the Hyper-V container) are very ok. Also docker builds both from command line and VS (which has it's own build system built around Docker, should you want to use it for .NET core, is very fast). Even on laptop systems.
So all in all, running Linux on Hyper-V is reasonable and well working. I do understand the personal dislike of some specific systems, or vendors, that's fine, I personally just don't use them at that point, instead of complaining how bad they are, but that is a matter of personal taste. Though it would be good to not mix up facts and subjective opinions.
Well you say that, and then mix up facts and subjective opinions. I don't have an opinion about Hyper-V being bad. I've tested it and unfortunately found it to be very bad, while hoping it wouldn't be.
Performance of vmware and virtualbox with WSL2 enabled (aka. hyper-v) is just too poor. Running linux in virtualbox with VB 6.1.18 is slow, it's not unsably slow, thus someone can claim that "it works!", however, it's slower than without WSL2, slowing it down into uncomfortable level.
VMWare, well, commercial solution has also problems, with their latest version, which is claimed to be "hyper-v & WSL2" compatible: communities.vmware.com/t5/VMware-W...
Tried it also myself, and running windows 10 in vmware with WSL2 enabled, is too slow (with virtualbox comically slow, that's reason for trying out vmware); with either case, not usable (i.e. comparable to sticking needles under the fingernails).
Yes. reason for experimenting with wsl2 was attempt of trying to run docker in windows (and so far it seems that I've to abandon it due to these performance problems caused by hyper-v in vmware & virtualbox).
I also tried Docker in Windows like that, and ended up with worse Docker performance than by running Docker in VMWare. So there's that too.
Other than the fs performance issue, I also encountered some network problems with wsl2 when accessing a VPN network or even just the host network.
I think the idea of wsl should be integrating Linux to Windows natively. Otherwise, why not just use a VM with a real Linux? But wsl2 is off this principle, as the network is separated as NAT; the fs is separated as ext4; a real Linux kernel might be also running somewhere... Everything are just like VM in wsl2.
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!
Janne, it is pitty we can't add disappointment smiles.
Your comment is very inaccurate, subjective and dislike kind of (someone called "alarmist") with a lot of "one man said, people has" .. these are just rumors. You also comment someone is ignoring "facts"...well, if you want to criticize, just provide facts, e.g. performance impact and comparison charts.
Community doesn't care about feelings, if you put such a comment please state the facts together with evidence, otherwise do not hoax people.
wsl --shutdown
Follow WSL2 FAQs docs.microsoft.com/en-us/windows/w...
[EDIT] - not sure what OS you're running and if you are talking about WSL2. I'm Windows11 and Ubuntu on WSL2 and I fairly satisfied.
Say I should put "facts together with evidence" and then spout some utter nonsense. Nice attempt to raise the dead - this thread is from eons ago, but you're still wrong and sound like a fanboy.
If you have issues booting a Linux ISO with a Hyper-V machine, try to switch "Safe Boot" to "Microsoft UEFI Certification Authority" and enable TPM.
Hyper-V is a hardware abstraction layer, exclusively claiming your processor's virtualization and providing an API for Type-2-virtualizers running on Windows. It's a feature Microsoft sells, true, but on the other hand it provides a layer of management and security for sysops to control when, what and how virtualization on a Windows system takes place in order to comply to ISO certification. After all, the hypervisor runs in ring 0 of the processor and you would like to have a restricted and safe environment to manage such applications with care and caution, especially on Windows...! You can change VirtualBox' para-virtualization to Hyper-V.
I don't defend Microsoft and how it is implementing hardware-accelerated virtualization in Windows, but they have architectural reasons for how they make hardware-accelerated virtualization available in Windows, even though I personally believe to pack Hyper-V with the higher-priced Enterprise and Pro editions while blocking any other access to the processor's hardware accelerated virtualization is some sort of robbery - almost every processor made and sold within the last decade enables some sort of hardware-accelerated virtualization.
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.
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.
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.
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.
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...
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