Skip to content

How to install WSL2 to your computer (Windows 11) ?

Installation Process (with PowerShell)

  • Start Powershell with Administrator rights (Run as Administrator)

  • WSL will be installed to your computer and in the default setting it will download latest Ubuntu

    If you already have wsl installed you should make sure that it is updated. Use command wsl --update to update it.

Bash
wsl --install
Installing WSL

Set default WSL version and check installed distributions

Bash
wsl --set-default-version 2
wsl --list --verbose
Installing WSL

See a list of the Linux distributions available through the online store.

Installing Debian to WSL

Lets install Ubuntu 24.04 and Debian Distripution. We will use Ubuntu 24.04 as main platform and Debian for testing. For this reason we will start by removing default Ubuntu from your pc

Bash
wsl --unregister Ubuntu
Bash
wsl --install --web-download --distribution Ubuntu-24.04
Bash
wsl --install --web-download --distribution Debian
Bash
wsl --setdefault Ubuntu-24.04

Updating WSL distripution using Powershell

Bash
wsl -d Ubuntu-24.04 -u root bash -c 'apt update ; apt upgrade -y'
wsl -d Debian -u root bash -c 'apt update ; apt upgrade -y'

Enabling systemd to your default WSL distribution Ubuntu-24.04

We are starting to use systemd, which brings WSL Linux closer to a virtual machine or physical installation

Bash
wsl -u root -d Ubuntu-24.04 bash -c "touch /etc/wsl.conf"
wsl -u root -d Ubuntu-24.04 bash -c "echo [boot] >> /etc/wsl.conf" 
wsl -u root -d Ubuntu-24.04 bash -c "echo systemd=true >> /etc/wsl.conf" 
wsl -t Ubuntu-24.04

Limiting amount of memory and cpu WSL can use. Change values as needed

Start Powershell with NORMAL user rights and copy all command in to it.

Bash
$contentToAdd = @"
[wsl2]
memory=4GB # Limits VM memory in WSL 2 to 4 GB
processors=2 # Makes the WSL 2 VM use two virtual processors
[experimental]
autoMemoryReclaim=gradual
"@

New-Item $home\.wslconfig
Add-Content $home\.wslconfig $contentToAdd
notepad++ $home\.wslconfig 

Last command did open Notepad++ and it is showing curant configuration $home.wslconfig . If there is need to change default values now is good opportunity to change them base on your computer resources.

How to backup WSL and remove it from the machine to save space

Export and import a Ubuntu distribution to a TAR file

Bash
wsl --export Ubuntu-24.04 "G:\My Drive\Ubuntu_wsl_backup_24.04.tar"

Import a new distribution

Bash
wsl --import Ubuntu-24.04-Base "c:\temp\" "G:\My Drive\Ubuntu_wsl_backup_24.04.tar"

Installing Debian to WSL

Uninstalling command is --unregister (Use only if needed)

No need to remove WSL distribution if everything is working

Bash
wsl --unregister Ubuntu-24.04
wsl --unregister Debian

Problem Solving

Update Windows computer and WSL. Start Powershell with Administrator rights as many times is needed. Go through repairs in order and test regularly.

Bash
# Install Windows update modules
Install-Module PSWindowsUpdate -Confirm
Set-ExecutionPolicy -Scope Process -ExecutionPolicy unrestricted
Import-Module PSWindowsUpdate
Get-WindowsUpdate
Install-WindowsUpdate
# Reboot as needed 
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Hyper-V still not working? Jump to "Hyper-V still not working?" otherwise, move on with WSL install

Let's check that WSL is installed

Bash
wsl --install

Update WSL kernel

Bash
wsl --update

Reinstall Ubuntu, Debian and Docker images. THIS WILL RESULT IN LOST DATA if you have not save data on your host machine!

Danger: data lost!

THIS WILL RESULT IN DATA LOST if you have not saved data on your host machine!

Bash
Stop-Process -Name "Docker Desktop" -Force
wsl --unregister Ubuntu-24.04
wsl --unregister Ubuntu
wsl --unregister Debian
wsl --unregister docker-desktop-data
wsl --unregister docker-desktop
wsl --set-default-version 2
wsl --install --web-download --distribution Ubuntu-24.04

Now we need to update WSL Ubuntu-24.04 to update

Bash
wsl -d Ubuntu-24.04 -u root bash -c 'apt update ; apt upgrade -y'
wsl --setdefault Ubuntu-24.04

Hyper-V still not working?

Forcing Hyper-v to start using Windows bootloader.

  • Start Powershell with Adminitrator rights (Run as Administrator)
Text Only
bcdedit /set hypervisorlaunchtype auto

More command can be found https://docs.microsoft.com/en-us/windows/wsl/basic-commands