Hello Newbies in Tech! Try This Powerful Tool by Microsoft to use Linux Effortlessly with Windows OS
Ajeet Yadav
Posted on February 4, 2020
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
Posted on February 4, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
February 4, 2020