How to Update Ubuntu in WSL from 18.04 to 22.04

Are you stuck with Ubuntu 18.04 for your WSL distribution? In this article, I finally managed to upgrade to the latest LTS version! 😎

4 min read
How to Update Ubuntu in WSL from 18.04 to 22.04
Photo by Monica Silvestre on Pexels.

For a long time, I was not able to run Node.js 18 on my desktop. When I choose one of its version with nvm, I always ran into an error stating that a library was missing: node: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.28' not found (required by node). I was stuck with the latest Node.js 16 version available... 😥

But, it was something that was bothered me. I couldn't use the new features of Node.js LTS version, and I hopped that somehow, it would resolve by itself. Disclaimer: it hasn't. I tried from time to time to upgrade, but my attempts have been unsuccessful. Until now. 😮

I'm now happy to says that I manage to install and to use Node.js 18. How? By upgrading my Ubuntu version of Windows Subsystem for Linux (WSL) from 18.04 to 22.04. After a new search, I stumbled on this answer on StackOverflow from hallexcosta and it worked for me! I was able to update to Ubuntu 20.04 and with another answer by NotTheDr01ds, I updated to Ubuntu 22.04 as well. So, thanks a lot to these people! 🥰

As it's possible that I would need to update my WSL distribution on another computer, I decided to write here the commands I used for posterity. It could also be useful for you if you aren't either on the latest version of Ubuntu. 😉

Without further ado, here is the complete procedure. 🤗

From 18.04 to 20.04

Before continuing, make sure that you aren't on the latest version of Ubuntu by running the following command in your WSL terminal:

lsb_release -a

# No LSB modules are available.     
# Distributor ID: Ubuntu
# Description:    Ubuntu 18.04.6 LTS
# Release:        18.04
# Codename:       bionic
Make sure that you're using Ubuntu 18 with the lsb_release command.
💣
Sometimes, I'm a little bit reckless, so I didn't do a backup. But if you don't want to take the same risks that I took, hallexcosta also provide the steps to create and restore a backup. 😉

Remove the Snapd package

"For me it was necessary to remove the snapd package, because ubuntu was not allowing me to upgrade to 20.04 LTS version." – hallexcosta

As I didn't want to take any chances, I uninstall as well the Snapd package. I don't know if it would have made a difference for me, but just to be sure... 😋

sudo apt purge snapd
This command remove and delete the snapd package, along with its configuration files.

According to its Wikipedia page, snapd is a tool used to package and to deploy applications. The procedure doesn't reinstall it, but at least, it is noted here that it has been removed. To add it back should be simple if it is needed. 🙃

Update and upgrade packages

Always make sure that the operating system is up-to-date before taking a major upgrade! 😄

# Get updated software list for Ubuntu
sudo apt update

# Apply updates and patches
sudo apt upgrade
The default commands to update all packages.

Install the update-manger-core package

"It’s essential to install this update manager core package this will trick the system into thinking there is a new LTS available and allow you to do an in-place upgrade." – hallexcosta

Again, I proceed exactly as I've been told. I wanted to quickly see if the procedure would work for me. 😅

sudo apt install update-manager-core

update-manager-core seems to be a simple package that manage release upgrades...

Install the new version

# Update Ubuntu
sudo do-release-upgrade
This command will check if there is a new version and will proceed to install it.

The command should take a couple of minutes to run. In my case, it has more than 600 MB to download. Go take a walk or grab a drink; once it's finished it will ask for a confirmation. 😉

Restart

Restart your computer to make sure everything has been updated and check if Ubuntu has been updated by typing the following command:

lsb_release -a

# No LSB modules are available.     
# Distributor ID: Ubuntu
# Description:    Ubuntu 20.04.5 LTS
# Release:        20.04
# Codename:       focal
You should now see that Ubuntu has been updated to 20.04, the next major LTS version after 18.04.

Unfortunately, at the time of writing this article, Ubuntu 20.04 is not the latest LTS version. But the steps from passing to Ubuntu 22.04 are smaller than those before. Let's see them. 🤗

From 20.04 to 22.04

With the three following commands, you should be able to upgrade to the latest LTS version:

# Get updated software list for Ubuntu
sudo apt update

# Apply updates and patches
sudo apt upgrade

# Update Ubuntu
sudo do-release-upgrade
You may recognize some commands that we have used to install Ubuntu 20.04.

Again, restart your computer and check if your Ubuntu distribution has been upgraded:

lsb_release -a

# No LSB modules are available.     
# Distributor ID: Ubuntu
# Description:    Ubuntu 22.04.2 LTS
# Release:        22.04
# Codename:       jammy
We are now on the latest LTS version of Ubuntu! 🥳

When Ubuntu 24.04 will be released, I hope that the previous procedure remains the same, as it's really simple. 🤞

Conclusion

After upgrading to Ubuntu 22.04, you should now be able to use Node.js 18 on your computer. Install it if it's not already done and run a simple command to check if the error about the missing library is gone.

# Install the Node.js latest version available
nvm install 18.15.0

# Check if Node.js is able to run without errors
node --version
# v18.15.0

Thanks again to hallexcosta and NotTheDr01ds! 🥰