How to setup WSL2 on Windows 10

Before Start

Enabling and configuring WSL2

Open the Windows PowerShell as Administrator (right-click and select Run as Administrator) and paste following commands to enable the WSL2 and the Virtual Machine Platform component.

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

After executing the commands above restart your computer, then download and install the WSL2 Linux kernel update package for x64 machines.

Open the Windows PowerShell and execute the commands below to set the default WSL to the version 2 and to limit how much memory is available to WSL.

wsl --set-default-version 2
wsl --shutdown
notepad "$env:USERPROFILE/.wslconfig"

With the .wslconfig file open add the following content and save:

[wsl2]
memory=4GB

You can increase the amount of RAM above depending on how much memory you have available on your system.

Instaling a Linux distribution

You can install a Linux distribution from the Microsoft Store> Below are some options:

After the distribution is installed, click on Launch to finish the installation. The installer will ask for a username and password to be used on the Linux environment.

Common issues

File operations are slow

The performance of WSL2 is worse than WSL1 when working with files across OS file systems. It’s recommended that you store and work with you files inside WSL. Comparison between WSL 1 and WSL 2.

Microsoft Terminal

Windows Terminal is a modern terminal that can be used with Command Prompt, PowerShell, and Windows Subsystem for Linux (WSL). You can install Windows Terminal from the Microsoft Store.

Visual Studio Code

Visual Studio Code is a source-code editor that offers an excelent integration with WSL. The first time you open the editor it will ask if you want to install the recommended WSL extensions.

After the installation you can open the VS Code from inside the WSL Ubuntu terminal using the command code. For example, to edit the files on the current directory you can execute:

code .

References:

Share your thoughts