eXXcellent solutions tech blog logoabout

WSL2 on Windows 10 - Setup and Experiences

Cover Image for WSL2 on Windows 10 - Setup and Experiences
Posted
by Lukas Reichert

Linux and Windows combined sounds like a perfect match. But does it actually work?

After a succesful installation WSL and its connections with VSC and Docker start automatically while the computer is booting. In general when you work with WSL2 you experience the Linux subsystem as a remote terminal, that can be called either in VSC or separately as bash. Because of that you normally access your files and installations via the terminal. However it is also possible to open them via the windows file browser if you use the command:

explorer.exe .

One might ask why I did not just use Linux native instead of the WSL, but to me one advantage of WSL is that I could use my preferred Programs (e.g. Word, OneNote).

As written in one of the above sections, it was fairly easy to integrate Visual Studio Code into my subsystem. I could easily clone remote repositories into my subsystem and open them in VSC.

Regarding storage, I did not run into any issue with my 16 GB RAM. However I would not recommend a smaller RAM, as my RAM regularly used 12 GB.

While working with WSL I did not encounter performance issues while performing commands like 'npm install' or running docker images. Though I have to admit that I am not able to compare the performance to Linux native as I have no experience in using it.

While I did not have major issues with WSL, there was the minor issue with symlinks, which I will describe later in greater detail. Another WSL2 issue worth mentioning is the installation of snap, which is required to e.g. install ChromeHeadless. I did not find a solution for this exact issue, but I could choose FirefoxHeadless for testing instead of Chrome.

At the end it will be mostly dependant on personal preferences if you choose or choose not to use WSL2. As a user that natively comes from Windows it was easier for me to dive into my work without the need to adapt myself to another UI.

Let us start by reading the official description of WSL2 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 traditional virtual machine or dualboot setup.

Install WSL2 and Ubuntu

Now, we can start by installing WSL2 and everything required for that. In order to do that you need to check if your Windows-Version is compatible for WSL2. You can check your Windows-Version by pressing the Windows-Key and the R-Key, which will open a search bar. Search for "winver" and check your version.

The minimum requirements are:

  • Windows 10, Version 2004 or higher
  • Build 19041 or higher.

First, we will install WSL1. Open your PowerShell as admin and execute the command below:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Next, we will update our WSL 1 to WSL2. Activate the feature „Virtual Machine Platform“ through executing the command below in PowerShell:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Reboot your system to complete the installation of WSL1 and the update to WSL2

Set WSL2 as your default version (in PowerShell):

wsl --set-default-version 2

If you get this message on your PowerShell: "WSL 2 requires an update to its kernel component"

Next, we have to install a Linux distribution. In order to do that,open your Microsoft Store and search for Ubuntu 20.04 LTS and click on „Install“ on its store page.

Once the download is completed, launch Ubuntu. The first time you open it, it will take a few minutes to install itself.

If the installation throws an error about uncompressed and unencrypted virtual hard disk files, please refer to the information on this site

Afterwards you will be asked to enter an username and a password for a default UNIX account

Go back to your PowerShell and use the following command in order to check whether your WSL2 Ubuntu is running

wsl –l –v

Install Docker

After installing WSL2, we need to download the latest release of Docker

Install your Download and follow its instructions to install Docker Desktop Docker will ask you to enable WSL2 at the beginning of the installation. Enable WSL2 to continue and start Docker Desktop.

In Docker, go to „Settings“ --> „General“ Make sure that the checkbox of „Use the WSL2 based engine“ is selected (if your system supports WSL2, this should already be enabled by default). Click Apply & Restart if you had to select it manually.

Once again, type this command in your PowerShell

wsl –l –v

Ensure your distribution runs in the WSL2 mode. If not set WSL2 as default version: wsl.exe --set-default-version 2

Now, go to „Settings“ --> „Resources“ --> „WSL Integration“ The WSL integration will already be enabled to your default WSL distribution. Type „wsl --set-default Ubuntu-20.04“ in PowerShell to change your default WSL distribution to the Ubuntu Additionally, you can enable WSL2 on additional distributions on the same page below. After that, click on „Apply & Restart“.

Developing with Docker, WSL2 and VSCode

Install VSCode

Install the „Remote - WSL“ extension This allows you to work with a remote server in the Linux distro and your IDE client still on Windows.

Open PowerShell Execute these commands:

wsl code .

These commands will open a new VSCode, that is remotely connected to your Linux distro.

Press CTRL + Ö while in VSCode to open the terminal and start working from your Windows machine.

Additional note regarding Symlinks

While working on a branch of a cloned repository I came across the issue, that my system did not recognize any of the symlink-files in the project. The cause of that problem was, that its important where the symlinks were created. To put it short, I deleted the symlinks and created new ones with the identical content via my subsystem.

For detailed information check out this site

Additional Information:

Though I did not use it, it is possible to have a GUI for the subsystem. Without a GUI you can access everything through the terminal or the windows file system. However, if you want a Linux GUI, please refer to this page.

If you want to run a Linux shell with multiple tabs, there is a way by using the common linux utility screen.

sudo apt install screen run sudo screen

With screen you can create multiple tabs:

ctrl-"a" "c"

and switch between them

ctrl-"a" "n"

or detach back to your primary shell

ctrl-"a" "d"

References:

The setup part of this article is based on multiple sources:

Image sources

The cover image used in this post was created by Ketut Subiyanto under the following license. All other images on this page were created by eXXcellent solutions under the terms of the Creative Commons Attribution 4.0 International License