Upgrading Debian to the next release may not be as straightforward as it is with Ubuntu. However, there is no need to worry, as the process is relatively simple if you follow a few key steps.
At the end of this guide, I will provide a consolidated command snippet that executes all the steps in one go, in case you are in a hurry.
Using APT for Debian Upgrades
Hello APT, my old friend.
APT is the system used by Debian to update the repository data and upgrade packages as well as the operating system to the next version.
Our main goal is to upgrade our current version as high as possible and then make the jump to the latest version of Debian, Debian 12 (Bookworm), at the time of writing this article.
First, we log into the system with our username that is not root. In my case, it is vico, and I proceed to run the command sudo su
in order to become a superuser.
A Note on Root Access and SSH Security
Root is usually disabled in Debian for SSH login, unlike Ubuntu, which allows this by default. It is recommended that root is not allowed to SSH into the host, as it is the user with the most permissions in the system. Malicious actors managing to break into this account can have dire consequences to your systems.
If sudo
does not work, like in my case where the system has minimal packages installed, then the command su
is to be run, which will then prompt me for the root password.
In the instance of sudo su
, it is your password that is required to elevate yourself to root.
If we run the command apt update, it will update the available packages and versions in the repositories that we have available for our system.
But what does that mean?
Updating Debian Repositories Before the Upgrade
Understanding Debian Repository Sources
The list of official Debian repositories is considerable. Each version of Debian has one available to it in order to separate supported packages per version.
Currently, the officially supported version is Debian 12 (Bookworm), while Debian 11 (Bullseye) up to Debian 8 (Jessie) are in some version of Long-Term Support (LTS) or Extended Long-Term Support (ELTS).
Since we want to keep up with packages and versions, let us do some changes first before we venture forth into getting ourselves to the latest and greatest version.
Editing sources.list
for the Upgrade
We will edit our sources.list file. This file controls the repositories and the available components, which in our case is only main.
To edit this file, run:
nano /etc/apt/sources.list
Nano is the text editor we can use to change our file easily without having to learn combinations of letters or commands beyond what is really required.
As the example shows, the list is pretty bare, so let us first change from bullseye to bookworm, and then we will add some additional components from where to get updates.
We have added the components contrib non-free to all the sources we have for our list of repositories. This ensures that we get additional packages that are not available with the default configuration.
To save the changes:
- Press CTRL+X
- A prompt at the bottom will state Save modified buffer? Press Y
- Make sure the name of the file is consistent with the one we are editing, so it should read:
/etc/apt/sources.list
Confirm by pressing Enter, and you will be returned to the terminal screen.
If we run apt update
, we may now have some packages to install. If we do, then run apt upgrade
and confirm the new packages so that we can then proceed with upgrading to Debian 12 (Bookworm).
Upgrading Debian 11 to Debian 12
Installing screen
to Prevent SSH Disconnect Issues
Before doing the whole process, let us take a small detour and install screen. This program will allow us to run the upgrade process and keep it running in case we lose our SSH connection.
Do this by running the command:
apt install screen
and press Y if prompted.
Automating the “Bullseye” to “Bookworm” Change
Let us go back to editing our sources.list file. Now, we need to change the name of the version from bullseye to bookworm, but as you can imagine, doing this by hand can take some time.
By using sed, we can easily edit all the instances of a single word in a text file, like the sources.list file, and replace it with another word. Use this command to change all instances of bullseye to bookworm:
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
The result will look like this:
Now that we have completed this step, we can run:
apt update
Depending on your internet connection, this may take some time and will reveal a number of packages that must be changed.
In our case, we have 308 packages ready to be installed. Depending on what you have installed, this may change considerably, so keep this in mind for your update.
Now that we are ready to proceed, we will run the screen
command and press Enter.
Running the command:
apt full-upgrade -y
will perform all the required changes to the system, including installing, updating, and removing packages without prompting any additional actions.
Once finished, you can exit the current screen.
Confirming the Debian 12 Upgrade
Run the command cat /etc/debian_version
to check the current version of Debian, which at the time of writing this article stands at 12.9 when prompted.
Or if you want to do something even more awesome, you can install neofetch by running:
apt install neofetch
neofetch
While we do not get the complete version of the OS, we can see that we are now using Debian 12 (Bookworm):
Updating System Name (Optional)
The name of the system continues to be the same so let us also change that so that it matches what we did.
Edit the file for hosts by running nano /etc/hosts
and then nano /etc/hostname
to change the names respectively from debian-11 to debian-12
/etc/hosts file
/etc/hostname
The changes will take effect on the next reboot but you can check if it is effective by running hostnamectl
As we can see on the command the name is set, as soon as we restart we will see it changed.
Automating the Upgrade Process
For those who want to automate the entire upgrade, use this script:
#!/bin/bash
apt update
apt full-upgrade -y
# Change Bullseye to Bookworm
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
# Add contrib and non-free repositories
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
apt update
apt full-upgrade -y
cat /etc/debian_version