3

I have Windows 10 (build 19042.1110) installed on my PC, and I wanted to install Ubuntu 20.04 using WSL (Windows Subsystem for Linux). So I enabled the WSL. However, I've not used the Microsoft Store to download Ubuntu: I downloaded the distribution directly from here (the .appx file)

Then, I followed these instructions and everything went fine. I created an account with password on Ubuntu, and did the updates/upgrades with apt get update and apt get upgrade.

Then I wanted to uninstall the distribution, but now I can't find it in the app&features panel nor in the start menu. If I search for "ubuntu" or "linux" on the start menu, I find nothing. I think this is due to the fact that I've not used the Microsoft Store.

How can I uninstall the distribution? I'd like to go back to how things were before installing Ubuntu. I've thought of using a system restore point, but I think this is unnecessary.

I'm pretty much a newbie in this area, so thank you for your help.

UPDATE:

I've run the command wsl --list --verbose to check and I got this:

  NAME             STATE          VERSION
* Ubuntu-20.04     Stopped        1

While the command Get-AppxPackage | Where-Object { $_ -like "*Ubuntu*" } didn't output anything.

Also, I found this, don't know if that's my case. However, the same page in my native language suggests using lxrun /uninstall /full for builds before the 1709 (16299) build, while for later builds it suggests using the Remove-AppxPackage cmdlet (which I don't know the sintax of).

(Sorry for the late update, thank you for your patience)

UPDATE 2:

I've used wslconfig /unregister Ubuntu-20.04 and everything went fine. I also reinstalled Ubuntu from Microsoft Store and uninstalled it from Apps & Features, and everything went fine. So thank you guys!

SuperFluo
  • 31
  • 1
  • 3
  • [wsl --unregister Ubuntu](https://superuser.com/questions/1440045/how-do-i-reset-a-manual-installation-of-windows-subsystem-for-linux/1440062#1440062) should remove it. If that doesn't work, provide the output, for `wsl --list --verbose` as an edit to your question[.](https://superuser.com/questions/1269458/how-to-install-ubuntu-on-windows-10-with-powershell?rq=1) – Ramhound Jul 21 '21 at 14:29
  • If the output to `wsl --list --verbose` is an empty list then you can simply delete the folder, since I am going to guess the reason you want to uninstall it, is because you were unable to figure out how to start it. – Ramhound Jul 21 '21 at 14:35
  • I don't recommend a `wsl --unregister` until we figure out if the appx is still installed. It probably can't hurt, but if the real goal is to "go back to how things were before installing Ubuntu", then it won't do that, since the Application itself would still be installed. Does a `Get-AppxPackage | Where-Object { $_ -like "*Ubuntu*" }` return any results? – NotTheDr01ds Jul 21 '21 at 15:22
  • Also, you must have *originally* had "Ubuntu" in the Start menu after installing the appx, right? That's how you start the "configuration" step that creates the actual WSL distribution and sets the user name. – NotTheDr01ds Jul 21 '21 at 15:25
  • @NotTheDr01ds - If the user wants the instance gone then running the suggest command wouldn't do anything they don't already want to have happen. Of course I suspect the instance was never actually registered, and the author actually got stuck, at some point in the manual creation of the instance and never actually successfully launched it. Which is the reason I submitted a comment, and requested more information, before I simply flagged this as being a duplicate of one of many answers that suggest the `wsl --unregister Ubuntu` command – Ramhound Jul 21 '21 at 16:44
  • @Ramhound Normally, I'd suspect that as well, but that doesn't *seem* to be the case here since the OP explicitly states that they were able to get through the step that creates the password, then entered the instance and ran `apt get update` and `apt get upgrade`. But that would mean that they *originally* had "Ubuntu" in the Start Menu (and Apps & Features), but it's gone now. Why? Perhaps the appx got uninstalled without properly cleaning up the instance, in which case you are right, `--unregister`, but otherwise it may need a `Remove-AppxPackage`. – NotTheDr01ds Jul 21 '21 at 17:45
  • @NotTheDr01ds - I can easily explain the reason it's not being found on the Start Menu, provided, the instance was registered. – Ramhound Jul 21 '21 at 17:53
  • @Ramhound Fair enough - I'd be curious myself. Can you go ahead and explain it? I assume you aren't waiting for that information in order to *answer* the question since, if I understood you correctly, you said you would mark it as a duplicate in that case. – NotTheDr01ds Jul 21 '21 at 18:00
  • @NotTheDr01ds - I am waiting on more information from the author. The start menu is explained by the fact, the author didn't pin a shortcut to the item, this would have normally been done when Ubuntu was installed from within Windows Store. This assumes they were successful in the configuration of the instance. – Ramhound Jul 21 '21 at 20:04
  • @Ramhound Sort of true, but again, not the case here based on the question. The OP mentioned that they did a "Search" on the Start Menu. That would find "Ubuntu" even if the user didn't pin it, since Ubuntu is a UWP app (whether installed by Appx package or via the Store), and Search goes through Apps & Features also (not just pinned entries). The OP also states that it wasn't in the Apps & Features. That's indicating a problem with the Appx installation (not the distribution installation), which is why I'd like to know the result of `Get-AppxPackage | Where-Object { $_ -like "*Ubuntu*" }`. – NotTheDr01ds Jul 21 '21 at 20:23
  • @NotTheDr01ds - You were quick on removing the answer you submitted. Unless the author updates their question, with the required information I need to author an answer, I probably won't return to this question – Ramhound Jul 21 '21 at 20:43
  • @Ramhound Yes, sometimes I start to type something up, then I realize that I'd like more information from the OP first (as I requested in the comment above). Instead of having to re-type everything later, I post it, then delete it. I can always undelete it when/if I get the additional info. Or delete it if it is no longer relevant. From watching the user's habits over the last few days (from the Stack Overflow post), they usually only get on here once every 24 hours or so. So I'm expecting a delay. Of course, you and I have been left hanging before, so anything could happen! :) – NotTheDr01ds Jul 21 '21 at 20:44
  • @NotTheDr01ds - I've updated the post with more info – SuperFluo Jul 23 '21 at 09:48
  • 1
    Do you want to just uninstall the Ubuntu instance, or do you want to completely uninstall WSL? It's unclear to me why you don't have the "App" installed any longer (to be able to just use the normal Windows "Uninstall" functionality). Did you by chance do a `wsl --import` at any point? Anyway, since the App isn't there, do as @Ramhound suggested and `wsl --unregister`. If you want to completely uninstall WSL, see [this answer](https://superuser.com/a/1619435/1210833). The `Remove-AppxPackage` isn't going to work for you since `Get-AppxPackage` indicates that it's not there. – NotTheDr01ds Jul 23 '21 at 15:06
  • 1
    @SuperFluo - If you want to remove the Ubuntu-20.04 instance just run the command `wslconfig /unregister Ubuntu-20.04` in an elevated PowerShell prompt. – Ramhound Jul 23 '21 at 15:11
  • I just want to uninstall the Ubuntu instance. Regarding WSL, I can just uncheck the relative feature in the Windows Features panel (Control Panel) after uninstalling Ubuntu, right? Also, no, I didn't do a `wsl --import`. Thanks for the help guys. – SuperFluo Jul 23 '21 at 17:10

1 Answers1

-2

You can use below script to uninstall Linux distros from system

# Uninstall Linux distributions installed on asset 

$packages = Get-AppxPackage -AllUsers | Where-Object {($_.Name -like '*Ubuntu*' -or $_.Name -like '*Debian*' -or $_.Name -like '*Fedora*' -or $_.Name -like '*Kali*' -or $_.Name -like '*Suse*' -or $_.Name -like '*Arch*' -or $_.Name -like '*Alpine*' -or $_.Name -like '*openSUSE*') -and $_.Name -notlike '*Microsoft.Windows.Search*'} 

if ($packages.Count -gt 0) { 

Write-Host "Linux distributions found:" 

$packages | Select-Object -Property Name, Publisher, Version | Write-Host 

foreach ($package in $packages){ 

Remove-AppPackage $package   

}  

Write-Host "Linux distributions removed completely with their files" 

} else { 

    Write-Host "No Linux distributions found." 

}