If you have ever wondered being able to use your favorite Linux commands/apps or tools on Windows, then you must try WSL.
Without wasting any time, let’s get to know what is WSL and understand what’s all this fuss about?
An overview of WSL
Following an official excerpt from Microsoft:
The Windows Subsystem for Linux lets developers run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a virtual machine.
With WSL, you can:
- Run your favorite Linux distro on Windows among
- Have a
zshshell accessible to you at all times in Windows.
- Install your favorite Linux software using the package managers among
What’s new in WSL 2?
WSL 2 is a new version of the architecture in WSL that changes how Linux distributions interact with Windows.
The primary goals of WSL 2 are:
- Increase in File System Performance
- Providing Full System Call Compatibility
WSL 2 was announced in May 2019, introducing important changes such as a real Linux kernel, through a subset of Hyper-V features.
However, it was available under Windows Insider program until the Windows May 2020 update.
With the Windows May 2020 update, WSL 2 is being rolled out to users outside of the Insider program and now everyone can access it.
For a complete list of differences between WSL 1 and WSL 2, see this official comparison guide by Microsoft.
Prerequisites for WSL 2
To use WSL2, you need to make sure you’re running Windows 10, updated to version 2004, Build 19041 or higher.
To check if you’re already running the May 2020 update:
- Go to Settings > System > About.
- Make sure you’ve the Windows version 2004 as can be seen in this screenshot.
If you’re not already running the May 2020 update, there are two ways to update your system.
- If you want to install the update now, Go to Settings > Update & Security > Windows Update > Check for Updates. If updates are available install them.
- If version 2004 isn’t available for your system right now, you can manually update your system using the Windows Update Assistant.
Windows Update Assistant is an official software provided by Microsoft to update your system without waiting to get the updates being rolled out to your system.
Once you’ve get your system updated, it’s time to install WSL and get started.
Installing WSL and updating to WSL 2
To install WSL on your machine:
- Open Powershell as Administrator and run the following two commands:
- Or if you prefer to enable these two using the UI, go to Settings > Apps > Optional Features. Scroll to the bottom and click on More Windows Features and turn on Windows Subsystem for Linux and Virtual Machine Platform in the list.
You now need to restart your machine and then move on to updating to WSL2.
So, you can bookmark this post now and come back here after restarting your system to continue.
Updating to WSL 2
There are two steps to updating to WSL 2:
- You need to install the Linux kernel provided by Microsoft.
- Set WSL 2 as the default version.
Install Linux Kernel by Microsoft
Please go to this link to install the Linux Kernel on your machine for WSL 2 to use.
Set WSL 2 as the default version
Run the following command in Powershell to set WSL 2 as the default version when installing a new Linux distribution.
You’ve now successfully upgraded to WSL 2.
From here you can now move on to install new Linux distributions or upgrade existing distributions if you’re already using WSL 1.
Using Linux Distributions in Windows
You can either install a new distro or upgrade existing distros (if any) to WSL 2.
Installing a new Linux distro
- Open the Microsoft Store.
- Search for your favorite Linux distribution.
- You can install from a wide-variety of distros available for WSL including
Fedoraand even the docker-favorite
- Click the Get button on the distro page to install the distro on your system.
Setting up the new distro
- Open up the distro using Start menu and search the distro name you just installed.
- The first time you launch a newly installed distro, a console window will appear and it’ll take a few minutes to setup.
- You’ll then need to create a user account by providing a username and password.
Upgrading your WSL 1 distro to WSL 2
If you already had WSL 1 installed, you can upgrade your existing WSL 1 distro to WSL 2.
You can check the WSL version of each distro you’ve installed by using the following command:
To upgrade a distro to WSL 2, set the distro version using the following command:
You’ll see the following message:
Conversion in progress, this may take a few minutes...
Although it says this may take a few minutes only, in reality, it might take hours to do that conversion. It all depends on the size of data within your distro.
If you have a large amount of data stored in the distro but it’s not important or only a small chunk of data is important to you, I would recommend you to delete the unimportant data by starting the image and deleting the data before updating the version.
If all of that data is unimportant, I would recommend to uninstall the distro and reinstall it.
Now, you can configure your own development environment within the WSL distro whatever way you like.
VS Code also provides a special official extension Visual Studio Code Remote — WSL.
This can help you out in using your existing VSCode configuration with WSL.
Also after the launch of WSL2 with Full System Call Compatibility, the Docker Team decided that their Docker Desktop for Windows will now be supported on WSL2 as it’ll lead to significant performance improvements and also they’ll be able to provide the same Docker Desktop on Windows Home edition as well.
You can checkout the Docker Desktop WSL2 here.
That’s all for this post.
Hope you liked it and it was helpful. 😀