how to upgrade Ubuntu packages in WSL alongside Microsoft Store auto-update

I started using WSL2 and installed Ubuntu without a specific version number. My understanding is that it will automatically upgrade to the next major LTS release (it's 20.04 now, and I assume it will be 22.04 next year).

Then, what about the packages inside? I can apt update and apt upgrade all of them, but Microsoft Store also auto-updates with newer Ubuntu builds, which I believe will overwrite some of my manual update. Should I leave them be and only upgrade the packages I installed by myself? What would be the best practice?


Note: Reusing some of my answer to this question. There's enough of a difference in the question to require a few changes, but some of the core concepts are the same.

The "automatic upgrade" part of the Store app is more than a bit confusing. Yes, "Ubuntu" (without a version number) in the Store "automatically updates", but that probably doesn't mean what you think it means. It took me a bit to get used to this concept myself.

This is a bit difficult to explain, but when you install "Ubuntu" (no version) from the Store, you actually end up with three different "installations":

  • WSL itself, of course, as a prerequisite. This is actually where the Linux kernel is installed, since it is shared between all installed WSL2 distributions/instances.

  • An "app package" with a rootfs package (install.tar.gz) in C:\Program Files\WindowsApps\CanonicalGroup.... You can see this by starting an Administrative PowerShell and running Get-ChildItem -Recurse 'C:\Program Files\WindowsApps\Canonical*' | Where-Object {$_.Name -eq 'install.tar.gz' }.

  • When run for the first time (via ubuntu.exe), the installer creates your actual WSL instance in your %UserProfile%\AppData\Local\Packages\CanonicalGroup....

What does an "automatic upgrade" of the Store app really do?

When there's a new update of the app on the Store, the only thing that gets updated on your system is the rootfs package. It does not change your installed instance. It does not automatically update any of the packages in your instance. It does not even update the WSL2 kernel.

You still need to run sudo apt update && sudo apt upgrade -y (or equivalent) to update the packages on a regular basis. Note that this does not include the kernel -- See below for how to do that.

As I think you can see from your question, this is a good thing. Otherwise, you'd be competing between the "Store" upgraded packages and those from the repo.

(Site note: Credit and thanks to u/zoredache on Reddit who originally clarified this for me.)

So what's the point?

Anyway, the upgrade of the Store package is pretty useless for most users unless you:

  1. Unregister the instance (which deletes all configuration) and re-configure it by re-running the ubuntu.exe command. When going through that initial configuration, the rootfs is unpacked, so you would get the "latest and greatest" from the Store at that point. However, note that Store releases are still fairly infrequent compared to package updates in the official repos. Even immediately after installing from the Store, you'll still almost always get a number of updates through apt.

  2. Want to use that install.tar.gz to create a second WSL/Ubuntu instance (using wsl --import). The newly created instance would then use the Store-updated rootfs. Again, the same caveats apply about the repo packages as in the first scenario.

Neither of these scenarios is very common. Even when the unversioned Store Ubuntu gets updated to (presumably) 22.04, it won't change your installed instance of 20.04, just the rootfs package.

At that point, you'll still need to run a sudo do-release-upgrade -d when you eventually want to upgrade to 22.04 (or an interim release).

Upgrading the kernel

Note that neither the Store update nor apt (or other package methods) update the WSL2 kernel. Since the kernel is part of WSL2 itself, and shared between all of the installed distributions, it's handled differently. Use:

wsl --update

... to check for and download any WSL2 kernel update.

That does assume that you are using the default kernel. You do have the option of downloading or building your own kernel from the WSL2 kernel source. It's been my experience that it can take a few days or weeks for the kernel update to become available via wsl --update, so if you want to grab the latest and greatest, you can. Then configure WSL2 to use that kernel via .wslconfig.

One more thing

All that said, the "Ubuntu" (unversioned) app still has one advantage, and that is that you won't need to worry about changing its name (like in that other question) when you eventually do upgrade to a later release. The "Ubuntu 20.04" version is going to always have the instance name Ubuntu-20.04, even if and when you manually upgraded it to something later.