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.
Set default WSL version and check installed distributions¶
See a list of the Linux distributions available through the online store.¶
Lets install Ubuntu 24.04 and Debian Distribution. 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¶
# Run the command below to install Ubuntu 24.04. Recommended.
wsl --install --web-download --distribution Ubuntu-24.04
# Run the command below. If you get the error message when trying to install with the above command.
wsl --install -d Ubuntu-24.04
# Run the command below to install Debian. Recommended.
wsl --install --web-download --distribution Debian
# Run the command below. If you get the error message when trying to install with the above command.
wsl --install -d Debian
Updating WSL distribution using Powershell¶
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
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
Upgrading WSL 1 to WSL 2 (only if yours WSL version is 1)¶
If you run wsl -l -v
and it shows your WSL version as 1, follow the steps below:
Note: If you manually installed WSL before the
wsl --install
command was available, you need to manually install the Linux kernel package. You can find the detailed guide at the link below: Detailed Installation Guide
Steps to Upgrade¶
- Install the Linux kernel package as per the detailed guide above.
-
Open PowerShell as Administrator and run the following commands:
-
Re-check your WSL version with the command below to ensure it has been upgraded to version 2:
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.
$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¶
Import a new distribution
Uninstalling command is --unregister (Use only if needed)¶
No need to remove WSL distribution if everything is working
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.
# 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¶
Update WSL kernel¶
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!
Now we need to update WSL Ubuntu-24.04 to update
Hyper-V still not working?¶
Forcing Hyper-v to start using Windows bootloader.
- Start Powershell with Adminitrator rights (Run as Administrator)
More command can be found https://docs.microsoft.com/en-us/windows/wsl/basic-commands