How to Remove and Install a Linux Distribution on Windows Using WSL Commands

Windows Subsystem for Linux (WSL) is a feature that allows you to run Linux applications natively on Windows 10 and Windows 11. WSL supports multiple Linux distributions, such as Ubuntu, Debian, Fedora, and more. You can install and manage these distributions using WSL commands in PowerShell or Windows Command Prompt.

In this blog post, I will show you how I used WSL commands to remove a Linux distribution that was having issues and then install a new and updated distribution. This process is useful if you want to switch to a different Linux distribution or upgrade to a newer version.

Removing a Linux Distribution Using WSL Commands

The first step is to remove the Linux distribution that you want to uninstall from WSL. To do this, you need to use the wsl --unregister command, which will delete the distribution and its files from your system. For example, if you want to remove Ubuntu, you can run the following command:

wsl --unregister ubuntu

You can also use the wsl --list command to see all the installed Linux distributions and their names. For example, the output of this command might look something like this:

Windows Subsystem for Linux Distributions:
Ubuntu (Default)
Debian

Installing a Linux Distribution Using WSL Commands

The next step is to install a new Linux distribution using WSL commands. To do this, you need to use the wsl --install command, which will download and install the Linux distribution of your choice from the online store. You can also specify the name of the distribution you want to install. For example, if you want to install Ubuntu 22.04, you can run the following command:

wsl --install Ubuntu-22.04

You can also use the wsl --list --online command to see the list of available Linux distributions that you can install from the online store. For example, the output of this command might look something like this:

Windows Subsystem for Linux Distributions:
Ubuntu-22.04
Ubuntu-20.04
Debian
Fedora
openSUSE

Setting the Default Linux Distribution and Version Using WSL Commands

After installing a new Linux distribution, you might want to set it as the default one that will launch when you run the wsl command. To do this, you need to use the wsl --set-default command, which will set the default Linux distribution for WSL. For example, if you want to set Ubuntu 22.04 as the default distribution, you can run the following command:

wsl --set-default Ubuntu-22.04

You might also want to set the version of WSL that your Linux distribution will run on. WSL has two versions: WSL 1 and WSL 2. WSL 2 is the latest and recommended version, as it offers better performance, compatibility, and features. To set the version of WSL for your Linux distribution, you need to use the wsl --set-version command, which will convert the distribution to the specified version of WSL. For example, if you want to set Ubuntu 22.04 to run on WSL 2, you can run the following command:

wsl --set-version Ubuntu-22.04 2

You can also use the wsl --list --verbose command to see the list of installed Linux distributions and their versions. For example, the output of this command might look something like this:

Windows Subsystem for Linux Distributions:
Ubuntu-22.04 (Default) (Running) Version 2
Debian (Stopped) Version 1

Conclusion

In this blog post, I showed you how I used WSL commands to remove and install a Linux distribution on Windows. This process is simple and convenient, as you can manage your Linux distributions using WSL commands in PowerShell or Windows Command Prompt. You can also switch between different Linux distributions and versions of WSL as you wish.

I hope you found this blog post helpful and learned something new. If you have any questions or feedback, please leave a comment below. Thank you for reading!