The New Way of Using Linux Seamlessly in Windows by WSL
Nil Madhab
Posted on March 23, 2021
Run Linux Kernel inside Windows without third-party softwares like VMWare, Virtual Box etc by Windows Subsytem for Linux
There is a very popular notion that Linux is the best OS for software development but Windows is more easy and comfortable to use. That must have made many of you to wonder if there were some way to run Linux Kernel below Windows GUI. If we could achieve this, we would get BEST of Windows and Linux in a single OS.
Turns out that there is one way to do this — WSL (Windows Subsytem for Linux)
How is WSL different than Dual Booting OR running a virtualization software ?
WSL vs Dual Booting
Dual Booting means installing multiple operating systems on a single computer, and being able to choose which one to boot.
This means that you CANNOT run both the OS at the same time.
But if you use WSL, you can use both the OS simultaneously without the need to switch the OS.
WSL vs Virtualization Software
There are many virtualization software available in the market today. Some of the most popular ones are Virtual Box, VMWare etc. Some of you may have even used one of them.
When you use VMWare or Virtual Box, you can run Linux (with GUI) inside Windows but it takes a lot of time to load. Also, if you need to access files stored in the main OS or internet from within the Virtual Machine (Guest OS), you need to install multiple drivers which makes it a very complex process.
WSL2 solves all of this. It takes less than a second to load the Linux Kernel. The process is same as opening CMD or PowerShell in Windows. Moreover, the file mounting/sharing, command running, and networking between your Windows desktop environment and the WSL2 environment is seamless and nearly instant on launch. You do not have to manage this environment — it will update alongside Windows.
Moreover, if you use WSL, you can use programs installed on Windows from the Linux kernel. One such example is VS Code. You can execute the command *code file_name *from the Linux Kernel to open a file in VS Code (which is installed in Windows).
How WSL looks ?
If you are a guy who believes more in seeing stuff rather than reading about that stuff, you can have a look at the photo mentioned below.
In the above image, you can see that a linux terminal is running on a windows PC just like Windows PowerShell.
How to Install WSL?
In this article, we will tell you how to enable WSL2 and install a Linux Distro of your choice. WSL 2 is the latest version of WSL and is even better. To know more, you can visit this Microsoft Docs link.
To install WSL 2, we will install WSL first and then upgrade to WSL 2.
There are two options available for installing Windows Subsystem for Linux (WSL):
- Simplified install (preview)
- Executing the command — wsl --install on a powershell terminal will install WSL without any additional steps. But this command requires that you join the Windows Insiders Program and install a preview build of Windows 10 (OS build 20262 or higher).
- The manual install steps can be used on any version of Windows 10.
Manually Installing WSL 2
Step 1 — Enable the Windows Subsystem for Linux
We must first enable the “Windows Subsystem for Linux” optional feature.
-
Run PowerShell as Administrator and execute the following command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
This command may take anywhere between 40–90 minutes to run. Moreover, not much will be output to the terminal when this command is getting executed. Hence, you must wear patience caps when you execute this command :)
- Do NOT restart the PC at this stage.
Step 2 — Check requirements for running WSL 2
To update to WSL 2, you must be running Windows 10.
For x64 systems: Version 1903 or higher, with Build 18362 or higher.
For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.
Builds lower than 18362 do not support WSL 2. Use the Windows Update Assistant to update your version of Windows.
Step 3 — Enable Virtual Machine feature
Before installing WSL 2, we must enable the Virtual Machine Platform optional feature.
-
Run PowerShell as Administrator and execute:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart your machine to complete the WSL install and update to WSL 2.
Step 4 — Download the Linux kernel update package
Download the latest package using the following link — WSL2 Linux kernel update package for x64 machines . If you’re using an ARM64 machine, please download the ARM64 package instead. If you’re not sure what kind of machine you have, open Command Prompt or PowerShell and enter: systeminfo | find "System Type".
Run the update package downloaded in the previous step. (Double-click to run — you will be prompted for elevated permissions, select ‘yes’ to approve this installation.)
Step 5 — Set WSL 2 as your default version
Run PowerShell and execute this command to set WSL 2 as the default version when installing a new Linux distribution:
wsl --set-default-version 2
Step 6 — Install your Linux distribution of choice
Open the Microsoft Store and select your favorite Linux distribution. The following links will open the Microsoft store page for each distribution:
Once the distribution’s page is opened on the Windows Store, select Get to install that distribution.
The first time you launch a newly installed Linux distribution, a console window will open and you’ll be asked to wait for a minute or two for files to de-compress and be stored on your PC. All future launches should take less than a second.
You will then need to create a user account and password for your new Linux distribution.
CONGRATULATIONS!
You’ve successfully installed and set up a Linux distribution that is completely integrated with your Windows operating system!
We would also recommend that you should install Windows Terminal. It is completely optional but would enhance your experience with WSL significantly.
Windows Terminal enables multiple tabs (quickly switch between multiple Linux command lines, Windows Command Prompt, PowerShell, Azure CLI, etc.), create custom key bindings (shortcut keys for opening or closing tabs, copy+paste, etc.), use the search feature, and custom themes (color schemes, font styles and sizes, background image/blur/transparency).
You can visit the following link to Learn more about Windows Terminal
To know how to install Windows Terminal, you can visit this link
Posted on March 23, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.