5

I am on WSL2 and had/have Ubuntu 18.04 installed. I went through a couple of steps to upgrade versions (enabling systemd, creating a symbolic link for apt-pkg, etc.). I was finally able to run sudo do-release-upgrade successfully and cat /etc/lsb-release currently returns 22.04.1 LTS.

However, my terminal, VS Code, and wsl.exe are all still showing version 18.04. How do I fix this so I'm only using 22.04.1?

$ cat /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"

$ wsl.exe -l --all Windows Subsystem for Linux Distributions: Ubuntu-18.04 (Default) docker-desktop docker-desktop-data

$ wsl --status Default Distribution: Ubuntu-18.04 Default Version: 2

I was following instructions here and running these commands or variations of them:

  • $ sudo apt update
  • $ sudo apt upgrade -y
  • > wsl --shutdown
  • $ sudo apt --purge autoremove
  • $ sudo apt install update-manager-core -y
  • $ sudo do-release-upgrade

I also ran the following command from here when I wasn't able to run reboot (before realizing I should just use wsl --shutdown in Powershell): cd /mnt/c/ && cmd.exe /c start "rebooting WSL" cmd /c "timeout 5 && wsl -d $WSL_DISTRO_NAME" && wsl.exe --terminate $WSL_DISTRO_NAME

I was getting an error saying "No module found named 'apt-pkg'", so I followed instructions here. That then gave me command not found error for do-release-upgrade, but I fixed that with this info.

I finally fixed the apt-pkg error by creating a symbolic link as described here so Ubuntu was directed towards python 3.6 instead of a more recent version.

I was then getting this error message when trying to run sudo do-release-upgrade:

A problem occurred during the update. This is usually some sort of network problem, please check your network connection and retry.
Err https://packages.cloud.google.com/apt cloud-sdk InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B53DC80D13EDEF05

I fixed that error by running curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

I was then finally able to run sudo do-upgrade-release, but at the very end it prompts to reboot, so I wasn't able to do that in the same session and ended up just restarting my computer, hoping that would do the trick. It didn't (seem to at least)--I was still seeing Ubuntu 18.04. I hadn't run cat /etc/lsb-release yet, so I don't know if it had updated there or not. Because I was still seeing 18.04 in the terminal and VSCode, I basically just started running variations of apt update/upgrade and do-release-upgrade, so it's quite possible I upgraded twice without realizing it.

Please let me know if any other info is needed.

  • try running an apt update, that may correct a half-completed release upgrade. Also many, many, more details on exactly what you did to get release-upgrade to work are needed (especially since you can't update directly from 18.04 to 22.04, only to 20.04 which is the next LTS release after 18.04, so did you do-release-upgrade twice?) – Esther Jan 17 '23 at 19:38
  • Updated. Let me know if anything is unclear! – coniferous Jan 17 '23 at 20:15
  • Welcome to Ask Ubuntu! When you say that VSCode and Terminal are still showing 18.04, is that via cat /etc/lsb-release as well? If so, then I'm wondering if you might have more than one distribution installed. Can you add the output of wsl.exe -l -v to your question? Thanks! – NotTheDr01ds Jan 17 '23 at 20:32
  • No, it shows 18.04 in the lower left of VS Code (and is the only distro available from what I can tell) and the shell in windows terminal also shows 18.04. I have done WSL.exe -l -v and it shows Ubuntu 18.04 and two stopped docker instances (from when I used that previously I assume). – coniferous Jan 19 '23 at 02:22
  • If I run cat /etc/lsb-release now, it shows 22.04, though – coniferous Jan 19 '23 at 02:23
  • @coniferous As a heads-up, using the @ symbol before a name will make sure that that person is notified of your reply. I didn't see yours until I rechecked the question manually. You, on the other hand, should receive notification for all comments on your own post. – NotTheDr01ds Jan 19 '23 at 20:04
  • Thanks @NotTheDr01ds I wish I had seen your post a few hours ago... I went ahead with someone else's suggestion and did a new install of Ubuntu (22.04) and am now trying to figure out how to get files out of a tarball and onto the new install (I've also already removed my old install) :/ – coniferous Jan 19 '23 at 20:18
  • @coniferous ok, hold on that and let me see if I can help – NotTheDr01ds Jan 19 '23 at 20:39
  • @coniferous can you post a new question about the tarball? give me details, and I can probably help you figure that part out – NotTheDr01ds Jan 19 '23 at 20:40
  • @NotTheDr01ds done: https://askubuntu.com/questions/1451112/how-do-you-efficiently-correctly-extract-data-from-a-tarball-into-a-new-ubuntu-d – coniferous Jan 20 '23 at 16:11
  • @coniferous Cool - I'm tied up for a couple more hours, but should get to reply this afternoon. – NotTheDr01ds Jan 20 '23 at 17:25

1 Answers1

2

Ok, I think I know what's happening now after the updates.

Ubuntu-18.04 is the distribution name. This name doesn't change; it's tied to the Store installer that was used originally to install it.

There are currently 4 versions of Ubuntu in the Microsoft Store:

  • "Ubuntu" (without a version name). Typically this would be the same as latest LTS release (Ubuntu 22.04), but it's still held back at the moment on Ubuntu 20.04. There are likely several reasons for this, that aren't important to this answer.

  • "Ubuntu-18.04": The oldest still-supported release. When you originally installed, apparently you chose "Ubuntu 18.04" instead of just the "Ubuntu" one.

  • "Ubuntu 20.04": Installing this package will install Ubuntu 20.04, even after the "Ubuntu" one has been changed to 22.04.

  • Ubuntu 22.04": Installing this package will install 22.04, of course.

However, any of those releases can be upgraded to another Ubuntu release, whether LTS or not. But, as mentioned above, upgrading doesn't change the name that was created for it. WSL itself has no knowledge of what is inside the distribution. You could actually install an Arch Linux (or other) distribution and call it "Ubuntu". WSL itself wouldn't know the difference (although it could cause issues with the Ubuntu installer in the future).

So ... how do you change the name of the distribution? Typically, you don't. But there are ways ...

I usually recommend creating your own named distribution based on the default installation:

  1. First, make sure you are using the latest WSL release installed from the Microsoft Store. On a fully updated Windows 10 or 11 system, install from here.

  2. Exit Ubuntu.

  3. From PowerShell, wsl --shutdown.

  4. Create a directory where you want your distribution to live. For example, from PowerShell:

    mkdir "$env:USERPROFILE\wsl\coniferous_ubuntu"
    cd "$env:USERPROFILE\wsl\coniferous_ubuntu"
    
  5. Still in PowerShell, find the location of your existing 18.04 distribution:

    Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ |
        ForEach-Object {
            (Get-ItemProperty $_.PSPATH) | Where-Object { $_.DistributionName -eq "Ubuntu-18.04" }
    } | Tee-Object -Variable ubuntuDist
    
  6. The information from the last command will be saved in $ubuntuDist. Run:

    wsl --import --vhd coniferous_ubuntu "$env:USERPROFILE\wsl\coniferous_ubuntu" "$ubuntuDist.BasePath"
    

    wsl --set-default coniferous_ubuntu

    wsl ~

  7. After starting this distribution, you'll notice that you are root, because WSL needs to be told the default user for each distribution. Do this by creating a /etc/wsl.conf file as in my answer here.

You should now have a distribution that is named by you, rather than after any particular version number (that can change).

Test the new distribution thoroughly, and once confident that the old one is no longer needed:

# WARNING:  Destructive operation.  All files in the distribution will be removed
wsl --unregister Ubuntu-18.04

You can also uninstall the "Ubuntu 18.04" from the Add or remove programs, which will free up some additional space.

At this point, VSCode should show your name for the distribution, and version upgrades shouldn't cause unwarranted confusion.

NotTheDr01ds
  • 17,888
  • The command for finding the location of the existing 18.04 distribution is missing a closing curly-brace. Where should it go? – coniferous Jan 23 '23 at 16:18
  • I added a second closing curly-brace after the first one. However, after running the command, I cam not seeing a value for the variable when I try to make sure it was correctly created (using echo $ubuntuDist or [System.Environment]::GetEnvironmentVariable('ubuntuDist')). Should the "Ubuntu-18.04" argument be changed to "coniferous_ubuntu" since that's what I see when I run wsl --list? – coniferous Jan 23 '23 at 19:01
  • @coniferous Ah, sorry about that - I did have problems copying it from PowerShell since there are some extra characters added. I apparently deleted a bit too much. – NotTheDr01ds Jan 23 '23 at 19:12