Skip to content

Installing and using WSL (Windows Subsystem for Linux)

Nowadays, as a web developer at d-centralize it is almost required to use Linux in your development environment. Luckily, for all the Windows users, Windows Subsystem for Linux (WSL) allows the best of both worlds. This guide will show you how to set it up.

Prerequisites

This guide assumes you are on a recent build of Windows 11 (20262+). To check your version and build number, select WIN + R, type winver, and select OK.

With Windows 11, Windows Terminal is installed by default. If you do not have Windows Terminal installed, please follow the guide here: https://learn.microsoft.com/en-us/windows/terminal/install

Get started

Open a PowerShell instance, and enter:

Terminal window
wsl --set-default-version 2
wsl --install

This enables the WSL and Virtual Machine Platform components, downloads and installs the latest Linux kernel, sets WSL 2 as the default, and downloads and installs the Ubuntu Linux distribution.

You will need to restart your machine to complete the installation process.

Set up Linux

After the restart a terminal window will open to set up your Linux distribution. Now you will be asked to create username and password.

  • These credentials have no bearing on your Windows username and password.
  • Note that whilst entering the password, nothing will appear on screen (blind typing).
  • This will be the default user, and considered the Linux administrator, with the ability to run sudo (Super User Do) commands.

It is recommended to keep your packages up-to-date. So after we reach the login screen we update and upgrade:

Terminal window
sudo apt update && sudo apt upgrade

Developing using WSL

By default, Git should already be installed (check using git --version). It is recommended to store all your projects on WSL. A recommended folder structure could be: ~/repositories/<organisation>/<repository>

Docker on WSL

To get started with Docker download Docker Desktop: https://docs.docker.com/desktop/windows/wsl/#download. It is also possible to install Docker on WSL directly without the GUI After installing a restart is required. After the restart open Docker Desktop and check if Use the WSL 2 based engine is checked.

Memory issues

In the case of issues with WSL2 stopping/crashing once it is using more memory, consider allocating more of your device’s memory to WSL2. This can be done by addin a .wslconfig file to the user folder found here by default: C:\Users\<user>. The .wslconfig file can then be opened using a text editor, after which you add the following snippet:

Terminal window
[wsl2]
#Limits VM memory to use no more than x GB, this can be set as whole numbers using GB or MB
memory=12GB

Replace 8 by a number of choice and save the file. By default, WSL2 will use either half your memory or 8GB, whichever is lower. After the file has been saved, restart WSL2 by either using wsl --shutdown or restarting your device.