50

I installed WSL 1, enjoyed having Linux on my PC, then discovered the limitations of the scarce interoperability over files between the two operating systems.

So I installed WSL 2 following the specs (enabled virtualization in BIOS settings and all the stuff) but the installation is not completely working, I cannot set it as default and not all the shell commands respond as expected.
I googled and somebody had similar issues, but not so many straightforward solutions are proposed (I guess it is still a relatively new case).

So I want remove WSL as deeply as possible and reinstall WSL 2 from scratch.

  • What is the most secure and advisable process to remove WSL completely?
  • Can WSL 2 be installed from scratch without installing WSL 1 before?
yodabar
  • 695

2 Answers2

45

Update: This is a bit of an outdated answer at this point. If you are running an older version of WSL that was installed prior to Windows 10 or 11 22H2, then this may be the correct answer on how to uninstall. However, if are running the Store-version (or UWP version) of WSL, then please see my newer answer (and/or other users' answers, if present).


Can WSL 2 be installed from scratch without installing WSL 1 before?

No. The base WSL support is required for WSL2.

What is the most secure and advisable process to remove WSL completely?

Here's the best info I have on removing everything related to WSL.

It sounds like you consider the existing instance a lost cause, but if you'd like to back it up for posterity, you can start with:

  • wsl --export <distroname> archivename.tar

Then remove the existing distro installation(s):

  • Any distro you installed from the Store, you should first remove through "Apps & Features" (a.k.a. "Add or remove programs") in Windows. This also goes for distributions installed manually via downloaded Appx package.

Then check to make sure nothing is left. From PowerShell or CMD:

  • wsl -l
  • wsl --unregister <distroname>

You may want to just install a new distro at that point from the Store. It's unlikely that any additional reinstallation of the other components is going to make a difference. But if you do want to remove them:

  • From "Apps & Features" (a.k.a. "Add or remove programs") in Windows, remove the "Windows Subsystem for Linux Update". I'm fairly certain this is the Linux kernel update. Probably reboot if you want to be sure it's fully gone before the next step.

  • From "Turn Windows Features on or off", disable "Windows Subsystem for Linux. According to the comments, a reboot may be required before the next step.

  • From "Turn Windows Features on or off" in Windows, disable the "Virtual Machine Platform". This is the WSL2 Hyper-V support.

  • Reboot.

When you are reinstalling from there, I'd appreciate it if you could confirm that "Windows Subsystem for Linux Update" returns to Apps & Features after installing the kernel update package (Step 4 in the Install doc). I will update this answer based on that info.

NotTheDr01ds
  • 28,025
40

This answer refers to the newer Store/UWP version of WSL. To confirm that you are using this newer version, run the following from PowerShell:

Get-AppxPackage |? { $_.Name -like "*WindowsSubsystemforLinux*" }

If you see a result, continue reading this answer. If you do not get a result, then you may be running an older release of WSL. See my older answer on how to completely uninstall that version.

For the Store/UWP version, the answer has changed:

Can WSL 2 be installed from scratch without installing WSL 1 before?

Yes, under Windows 11 22H2, a wsl --install will by default only install WSL2. To install WSL1, you must add wsl --install --enable-wsl1.

Note that the --enable-wsl1 option is not available on Windows 10, even on a fully updated system that is otherwise compatible with the newer WSP version. On Window 10 (19045.2311), WSL1 is still automatically installed and enabled with wsl --install.

What is the most secure and advisable process to remove WSL completely?

Here's the best info I have on removing everything related to WSL. This should make sure that (a) all features are removed, and (b) all disk space is reclaimed.

Uninstall

  1. Optionally, back up existing distributions:

    It sounds like you consider the existing instance a lost cause, but if you'd like to back it up for posterity, you can start with:

    wsl --export <distroname> archivename.tar
    

    Confirm all distribution names to backup via wsl -l -v.

    Alternatively, copy out just the files that are important to you from the distribution to a safe place outside the distribution. Usually, this will include everything in your home directory, but also look at /var and /etc for any files you may want to keep.

  2. If you have Docker Desktop installed, see Docker documentation for information on how to back up any Volumes, Containers, etc.

  3. Optionally, confirm validity of backed-up distribution(s):

    Of course, if the backup is important to you, then confirm that it works with a wsl --import into a new name.

  4. Unregister existing distributions:

    For each distribution found with wsl -l -v, remove it via:

    wsl --unregister <distroname>
    

    Warning: This is a destructive and irreversible operation unless you have a valid backup as above.

  5. Identify any distribution packages (applications) installed from the Store:

    Go to Settings -> Add or remove programs and look for any distributions you may have installed from the Store (Ubuntu, Debian, Alpine, openSUSE, or others). This is actually separate from the distribution you unregistered above. These packages include the Distro Launcher and rootfs that originally created your distribution (e.g. ubuntu2004.exe).

    Alternatively, you can run the following command from an Administrator PowerShell (PowerShell Core is recommended):

    Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ |
        ForEach-Object {
            (Get-ItemProperty $_.PSPATH) | Select-Object DistributionName,BasePath
        }
    

    This should list all of the installed Distribution packages on your system.

  6. Then uninstall each distribution using Add/Remove Programs.

    Under older Windows versions, uninstalling these packages also uninstalled the corresponding distribution, leading to some unintended data loss. It appears most recent systems require these to be removed in two separate steps, which is a good thing.

  7. Also in Settings -> Add or remove programs, look for, and remove, any "Windows Subsystem for Linux" apps. This may include:

    • Windows Subsystem for Linux: The main WSL package itself. (Note: You may not see this package under the latest release. If not, it has probably been transitioned to a System Component and can be uninstalled in the next step.)
    • Windows Subsystem for Linux Update: Updates to the kernel package for older versions (in-box, that came as a Windows feature) versions of WSL.
    • Windows Subsystem for Linux WSLg Preview: The WSLg feature that came with Windows 11.
  8. Go to Settings -> System -> System Components (or, from the Windows Menu, search for System Component Settings).

    If "Windows Subsystem for Linux" is in this list as a System Component, then, from PowerShell, run:

    wsl.exe --uninstall
    

    This will require Administrator elevation. The elevation dialog could pop up in the background, so be on the looking for a flashing title in the Windows Taskbar.

  9. It might be best to reboot at this point to release any other in-use files.

  10. Next, go to Settings -> Turn Windows features on or off.

  11. If they are enabled, disable:

    • Virtual Machine Platform
    • Windows Subsystem for Linux

    Windows will likely prompt to reboot.

  12. After rebooting, confirm that all of the above items were removed successfully. At this point, any wsl command should simply return the default "install" help text.

Reinstall

The recommended way to reinstall from here is:

  • Open an elevated PowerShell. It is best to do this as your regular user, in an administrator elevated session, rather than as the separate Admin user.

    wsl --install
    

    By default, this will:

    • Re-enable the Virtual Machine Platform
    • Install the latest WSL release from the Microsoft Store. This release now includes the kernel directly, rather than requiring a separate installation step as before.
    • Install the default Ubuntu distribution from the Microsoft Store

    Also see wsl --help for additional installation options. For instance, you can skip the installation of a distribution at this stage or select a different distribution.

NotTheDr01ds
  • 28,025