25

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
  • 445
  • 2
  • 5
  • 9

2 Answers2

29

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
  • 17,574
  • 4
  • 44
  • 81
  • Thanks for the detailed info, I will come back to confirm the process and the last point in particular. – yodabar Jan 21 '21 at 07:55
  • 1
    FWIW I did your steps and I did the 'simplified install' (`wsl --install` on the command line) and it reinstalled the kernel update package automatically. – Eddie Parker Sep 10 '21 at 10:00
  • @EddieParker Thanks! That also reminds me that I need to go back through my old answers and update them for `wsl --install` since it's now GA. – NotTheDr01ds Sep 10 '21 at 15:19
  • These steps successfully unborked my WSL install that was borked by upgrading to Windows 11. – Techrocket9 Oct 30 '21 at 05:47
  • @NotTheDr01ds To answer to your question, "Windows Subsystem for Linux Update" is not visible in Windows Apps & Features after installing the kernel update package, in my PC. – yodabar Nov 09 '21 at 11:20
  • If you go the export/import route, you can restore your default user after import by running `ubuntu config --default-username ` from CMD – Robin De Schepper Feb 11 '22 at 18:20
  • 1
    @RobinDeSchepper True, but that does assume that (a) the distribution is Ubuntu (the non-versioned one from the Microsoft Store) and (b) it was installed from the Store. For Store distros, it could also be `ubuntu2004` or `alpine` or `debian` or others. I tend to prefer the `/etc/wsl.conf` method of setting the default user as described [here](https://superuser.com/a/1627461/1210833). That also has the advantage of (a) working even if the distribution wasn't installed from the store, and (b) any `--export`'s you do with that image from that point on will "remember" the default user. – NotTheDr01ds Feb 11 '22 at 18:30
  • Microsoft has made it clear through actions that the way forward for Windows Subsystem for Linux (WSL) will to install it through the Windows Store. In fact evidence of this, is simply that, WSL installed through the Windows Store on Windows 10 now supports WSLg while installing WSL outside of the Windows Store seemingly does not. If you have a WSL problem, and are reading this comment, because you read the answer try installing WSL through the Windows Store might resolve your problem – Ramhound Nov 29 '22 at 22:57
  • I had to reverse steps 2 and 3, removing "Windows Subsystem for Linux" before it would let me remove "Virtual Machine Platform". (I'm on Windows 10 and everything was manually installed - I'm removing everything to install it from the store instead.) – mindplay.dk Feb 25 '23 at 11:43
  • @mindplay.dk Thanks - I updated the instructions based on your experience. – NotTheDr01ds Mar 02 '23 at 14:25
13

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.

  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. 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.

  3. 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.

  4. Uninstall 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).

    Uninstall each distribution.

    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.

  5. 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
    • 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.
  6. It might be best to reboot at this point to release any other in-use files.

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

  8. If they are enabled, disable:

    • Virtual Machine Platform
    • Windows Subsystem for Linux

    Windows will likely prompt to reboot.

  9. 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.

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
  • 17,574
  • 4
  • 44
  • 81
  • 1
    `wsl --install` didn't work for me (Windows 10 64 bit), it required me to re-install both options (Virtual Machine Platform, Windows Subsystem for Linux) via "Turn Windows feartures on/off" again. Note that if you're done with the reinstallation you might want to run `wsl --set-default-version 2` as well to re-enable WSL2 per default. But apart from that, it worked just fine! You might want to create a [`.wslconfig`](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig) file as well to limit resources, to avoid slowing down your PC too much. – Matt Feb 28 '23 at 09:56
  • @Matt Odd - What happened with `wsl --install`? Note that recent versions of Windows 10 and 11 both should default to installing WSL2 from the [Microsoft Store](https://aka.ms/wslstorepage) rather (or in addition-to, for 10) the Windows feature. This will get you the latest release, while the Windows features are all over a year old now. – NotTheDr01ds Feb 28 '23 at 14:34
  • Well, odd indeed: In my case `wsl -- install` just spitted out the error message that "Virtual Machine Platform and Windows Subsystem for Linux" need to be installed - and did nothing else. – Matt Mar 01 '23 at 08:07
  • So far so good. I used wsl --install and it automatically began "Installing: Virtual Machine Platform" and "Installing: Windows Subsystem for Linux" – john stamos Jun 23 '23 at 15:38
  • 1
    I needed to re-enable Windows Subsystem for Linux via "Turn Windows features on/off" before wsl --install would work for me. – mpersico Aug 26 '23 at 17:40