December 22, 2024

How to Install a Desired Linux Distribution (Ubuntu) in Windows Subsystems for Linux -WSL

In this Windows and Linux tutorial, we explain how to install a desired Linux distribution in Windows Subsystems for Linux (WSL1 or WSL2). The YouTube tutorial accompanying this webpage is given below.

Prerequisites

Make sure that WSL2 is installed on the system. You can do that by opening a PowerShell terminal in the administrator mode (click on Start and search for PowerShell, then do the right click on PowerShell and select “Run as administrator”), and by typing:

wsl --install

Then, after restarting the system, you will be able to use WSL. Note that with WSL there will be a default Linux Ubuntu version installed. We can change the default distribution and install any other supported distribution.

Install Desired Linux Distribution in WSL1 or WSL2

First, double-check the default Linux distribution that comes with WSL. To do that, open WSL by clicking on Start and by searching for WSL, or you can also search for Ubuntu. Once you start the WSL you will be automatically redirected to the default Linux distribution. To check the Linux distribution, type

lsb_release -a

And you will see your default distribution. If this is the distribution you need, then you do not need to do anything. Otherwise, let us install the distribution you need.

To list all available Linux distributions that can be run through WSL, open a PowerShell in the administrator mode and type:

wsl --list  --online 

You will see this

From the list, you need to select the Linux distribution that you want to install. After that, you need to type in PowerShell:

wsl --install -d <Distribution Name>

For example, to install Ubuntu 24.04 you will need to type

wsl --install -d Ubuntu-24.04

After that the distribution will be installed, and you need to set your username and password. You will be automatically logged in the distribution. Exit the distribution by typing “exit”. You can always start this distribution, by clicking on Start and by searching for the correct Linux distribution you just installed.

To check a list of installed Linux distributions and check which version of WSL you are running, go back to the PowerShell and type

wsl -l -v

The start symbol denotes the default distribution. To change the default distribution, type this

wsl --setdefault <Distribution Name>

In our case, to set the default distribution to be Ubuntu 24.04, we need to type

wsl --setdefault Ubuntu-24.04

After that, we can type

wsl -l -v

To verify that the default distribution is changed. The output is