35

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
  • 545

2 Answers2

36

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
  • 21,923
  • 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 <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. 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
  • 1
    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
  • FYI, you could probably combine steps 2 and 3 instead of reversing them. As long as you get all the dependencies, you can add or remove several Windows Optional Features in a single operation; maybe save a little work and a reboot, and not worry about which depends on which. (Here, WSL depends on VMP.) – Andrew Janke Mar 21 '24 at 04:59
  • @AndrewJanke Absolutely - It's certainly possible to combine them into one step, as well as to not reboot between some. I left them separate in this case because the user in the original question was having an issue with WSL2 and wanted to full uninstall so that they could reinstall to try to fix it. The instructions may be a bit "overkill" because of that, but in cases like this, I prefer to take each step separately. As seen in the comments, it did surface a problem for at least one user. – NotTheDr01ds Mar 21 '24 at 10:36
  • Totally sensible. – Andrew Janke Mar 21 '24 at 17:10
23

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
  • 21,923
  • 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 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 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
  • After uninstalling everything I downloaded and ran the MSI file for the latest WSL2 release. Everything worked without having to re-enable Virtual Machine Platform or Windows Subsystem for Linux under Settings. – Mike Lowery Jan 29 '24 at 19:33
  • FWIW: I had a similar problem as Matt where, on Win 10 22H2, after a manual uninstall and then wsl --install, running Ubuntu gave me an error "Error: 0x8007019e The Windows Subsystem for Linux has not been enabled". But my WSL was hosed at that point, and I couldn't get it working with any of the steps in this or the other answer, and Ubuntu would give "Something went wrong; An irrecoverable error happened" messages in a "Ubuntu WSL" window with a big frowny-face icon. (That one's new to me.) I ended up formatting my disk and doing a fresh Windows 10 22H2 install. Then it worked fine. – Andrew Janke Mar 19 '24 at 01:47
  • That was on a Windows 10 22H2 machine, fully up to date, but with a WSL that was a few years old and originally installed the pre-Store way, and later upgraded to WSL2 with wsl --update or the like. I think there I missed the step of removing WSL from the Settings > Apps & Features thing. On the fresh Win 10 installs, I could not reproduce this error by intentionally omitting uninstall steps. I'm guessing the old pre-Store installer left WSL in a state the current wsl --install couldn't handle in combination with missed uninstall steps, but the current installer doesn't do that? – Andrew Janke Mar 19 '24 at 01:51
  • @AndrewJanke Really just no way of telling. Even on the older WSL, I saw cases where Store installs of distributions (and even other apps) just wouldn't take effect. I'm sure there's some solution short of reinstalling Windows, but sometimes that's just the best/easiest path to take to fully recovery. – NotTheDr01ds Mar 19 '24 at 11:37