Upgrade WSL Ubuntu version from 18.04 LTS to 22.04 LTS

Tags
Published
Archived
Archived
Author
 
I've been using Ubuntu 18.04 LTS and Visual Studio Code (VS Code) as my development environment for a long time. However, since Visual Studio Code (VS Code) version 1.86, it has stopped supporting older glibc versions. A warning is thrown when the operating system running VS Code doesn't meet the requirements.
 
Although the official documentation offers several solutions for those hesitant or struggling to upgrade their OS version, since my Ubuntu version is no longer officially supported, I decided to upgrade it.

Ugrade strategy

It seems that there are no way to upgrade Ubuntu 18.04 LTS to Ubuntu 22.04 LTS directly. Therefore I will follow this Medium blog post and the official Ubuntu documents (link1, link2), to upgrade the Ubuntu version by version.

Before upgrade

We should backup all of our data before the upgrade process.

Upgrade Ubuntu 18.04 LTS to 20.04 LTS

Upgrade installed software

According to the Ubuntu official documents, we should upgrade all installed software first. Following the Medium blog post, we can execute the following commands:
sudo apt update sudo apt upgrade sudo apt dist-upgrade sudo apt autoremove
 
Next, we need to comment out the unofficial software repositories in /etc/apt/sources.list to prevent installing incompatible software versions after upgrading the OS. Use the following command:
sudo vim /etc/apt/sources.list
 
In my case, I comment out these lines:
# deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable # deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-15 main # deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main # deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
 

Enable systemd

The do-release-upgrade pretty much assumes systemd exists, daemons can be stopped and restarted with systemctl, and snaps work (among other things).
 
Therefore, before running the upgrade command, we must either uninstall snapd or enable systemd in WSL. Otherwise, we will encounter an error message like this after running the upgrade.
=== Command terminated with exit status 1 (Sun Apr 21 13:35:31 2024) ===
 
I choose to enable systemd. To do that, edit the /etc/wsl.conf and add the following lines:
[boot] systemd=true
💡
You can execute sudo vim /etc/wsl.conf to edit the file.
 
After modifying the file, exit the WSL terminal and then open PowerShell to run the following command to shut down WLS:
wsl --shutdown
 
Now, we can execute this command in PowerShell to re-open WSL:
wsl
 

Execute the upgrade command

Finally, execute the following command to start upgrade to Ubuntu 20.04 LTS:
sudo do-release-upgrade
💡
If prompted, press Enter to continue the upgrade process.
 
Next, enter y to continue the installation:
Do you want to start the upgrade? 18 installed packages are no longer supported by Canonical. You can still get support from the community. 31 packages are going to be removed. 250 new packages are going to be installed. 787 packages are going to be upgraded. You have to download a total of 530 M. This download will take about 3 minutes with your connection. Installing the upgrade can take several hours. Once the download has finished, the process cannot be canceled. Continue [yN] Details [d]
 
After the installation is complete, run this command to verify if Ubuntu has been upgraded to 20.04 LTS.
 
Remove obsolete packages? 423 packages are going to be removed. Removing the packages can take several hours. Continue [yN] Details [d]
 
System upgrade is complete. Restart required To finish the upgrade, a restart is required. If you select 'y' the system will be restarted. Continue [yN]
❯ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: 20.04 Codename: focal

Upgrade Ubuntu 20.04 LTS to 22.04 LTS

Same as the previous steps, we should upgrade all installed software first.
sudo apt update sudo apt upgrade -y sudo apt dist-upgrade -y sudo apt autoremove -y
 
Next, execute the following command to upgrade Ubuntu 20.04 LTS to 22.04 LTS:
sudo do-release-upgrade
 
Do you want to start the upgrade? 14 installed packages are no longer supported by Canonical. You can still get support from the community. 16 packages are going to be removed. 124 new packages are going to be installed. 676 packages are going to be upgraded. You have to download a total of 393 M. This download will take about 2 minutes with your connection. Installing the upgrade can take several hours. Once the download has finished, the process cannot be canceled. Continue [yN] Details [d]y
Processing snap replacements refreshing snap lxd Searching for obsolete software Reading state information... Done Remove obsolete packages? 94 packages are going to be removed. Continue [yN] Details [d]y
❯ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy