How to upgrade from Ubuntu 20.04 LTS to 22.04 LTS
Upgrading from Ubuntu 20.04 LTS to 22.04 LTS brings significant benefits for your system’s performance, security, and long-term support. Ubuntu 22.04 LTS is supported until 2027, and includes important updates such as improved hardware compatibility and faster boot times. It also features enhanced security, updated applications, and better support for modern technologies — ensuring your systems remain stable, efficient, and secure for the future. This upgrade is a smart step to keep your infrastructure current and well-supported.
You should ensure at least 20 GB of free disk space before starting the upgrade. It's also strongly recommended to back up your important files beforehand, just in case any issues arise during the process.
Upgrade Current Packages
First of all, it's a mostly optional but recommended step to upgrade your currently installed packages. Doing so helps to reduce the differences between your current system and the new Ubuntu version, which can minimize potential issues during the upgrade process.
If you're logged in as the root user, you don't need to use the sudo
command, as you already have full administrative privileges. However, it will work anyway, so you can just copy and paste the commands below.
First of all, you need to update the package repositories to ensure that you'll get the latest updates.
sudo apt update
To perform an an update for all available packets in their newer version, run the following command.
sudo apt upgrade -y
When everything is done, it is recommended to restart your system before proceeding.
shutdown -r now
Verify Current Running Version
If you're currently using Ubuntu 20.0 LTS4, you can follow this tutorial to upgrade to 22.04. However, if you're already on 22.04 LTS and want to upgrade to 24.04 LTS, please refer to the separate tutorial specifically for that upgrade path.
You can verify the version you are currently running by this command:
lsb_release -a
The output should look similar to the following one.
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
Open Port for Failover SSH Server
During the upgrade, the Ubuntu upgrade routine opens a failover SSH server you can use to access your system in case anything goes wrong during the upgrade and the actual SSH server is being affected by that. While it's not required to successfully upgrade your server, it's strongly recommended to either follow the instructions below or to ensure that you have local access to your server via a VNC Console, like we offer for our customers.
The default port for the failover SSH server is port 1022/tcp
. If you are using Ubuntu's default firewall ufw
, you can simply type the the following command to make sure that the firewall allows access to said port:
sudo ufw allow 1022/tcp
If you haven’t enabled ufw
manually, it should be inactive by default. You can verify its status using the following command:
ufw status
In case it's disabled, you don't need to do anything.
Perform The Upgrade
To perform the actual upgrade, Ubuntu provides its own upgrade tooling. All you need to do to perform a full system upgrade is running the command below. You don't need to change any package repositories like you may have been done with other operating systems like Debian.
sudo do-release-upgrade
The output should look like that:
Reading cache
Checking package manager
Continue running under SSH?
This session appears to be running under ssh. It is not recommended
to perform a upgrade over ssh currently because in case of failure it
is harder to recover.
If you continue, an additional ssh daemon will be started at port
'1022'.
Do you want to continue?
Continue [yN]
Enter Y to continue.
Starting additional sshd
To make recovery in case of failure easier, an additional sshd will
be started on port '1022'. If anything goes wrong with the running
ssh you can still connect to the additional one.
If you run a firewall, you may need to temporarily open this port. As
this is potentially dangerous it's not done automatically. You can
open the port with e.g.:
'iptables -I INPUT -p tcp --dport 1022 -j ACCEPT'
To continue please press [ENTER]
Now press Enter to continue.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Hit http://mirror.servinga.com/ubuntu focal InRelease
Hit http://mirror.servinga.com/ubuntu focal-updates InRelease
Hit http://mirror.servinga.com/ubuntu focal-backports InRelease
Hit http://mirror.servinga.com/ubuntu focal-security InRelease
Hit https://mirror.servinga.com/vps2day stable InRelease
Fetched 0 B in 0s (0 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Checking for installed snaps
Calculating snap size requirements
Updating repository information
No valid mirror found
While scanning your repository information no mirror entry for the
upgrade was found. This can happen if you run an internal mirror or
if the mirror information is out of date.
Do you want to rewrite your 'sources.list' file anyway? If you choose
'Yes' here it will update all 'focal' to 'jammy' entries.
If you select 'No' the upgrade will cancel.
Continue [yN]
Press Y again to continue.
Do you want to start the upgrade?
4 packages are going to be removed. 89 new packages are going to be
installed. 568 packages are going to be upgraded.
You have to download a total of 635 M. This download will take about
2 minutes with a 40Mbit connection and about 16 minutes with a 5Mbit
connection.
Fetching and installing the upgrade can take several hours. Once the
download has finished, the process cannot be canceled.
This is the point where the upgrade will begin. Once you've started the upgrade process, there’s no turning back. If you're ready to continue, simply press Y.
The upgrade can take a while depending on your internet connection and other factors.
You should see a highlight Yes
and press Enter to allow the system to restart services without prompting again.
It's recommended that you let the upgrade helper carry out those restarts on its own.
During the upgrade process, you might be asked what should happen with configuration files of services you have installed. If there's a service where you altered the configuration file, you might either choose to keep the local version currently installed or perform a merge of the proposed changes by the maintainer and your own changes. If the service in question gets a major version upgrade, keeping you current configuration might brick the service if the configuration syntax changed or when there are new configuration options added or old ones being deprecated.
80 packages are going to be removed.
Continue [yN] Details [d]
These packages are no longer needed. Press Y to proceed with the deletion of the old packages.
To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.
Continue [yN]
Press Y again to restart your server and complete the upgrade.
Verify New Running Version
By running the command below a second time, you should be able to confirm that your server now indeed no longer runs on its old Ubuntu version, but rather on a new Ubuntu 22.04 LTS.
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy