The process of upgrading from Debian 11 to Debian 12 is fairly straightforward for those that have been doing it for a while, but for those that are not familiar, it can be a daunting task. In this article, I’ll present two different options for upgrading: Manual and Automated. The automated (scripted) process is the same as the manual process, so please work the manual process in your environment before using the script. As always, please be sure you’ve got a proper backup of your machine before starting the process!
1: Update system
Before doing the upgrade, you must ensure your system is running the current latest packages within your current version.
sudo apt update && sudo apt upgrade && sudo apt full-upgrade
2: Make a backup of your current /etc/apt/sources.list file
In case anything goes wrong while updating the sources.list file, it’s always good to have a backup.
cp /etc/apt/sources.list /etc/apt/sources.list.orig
3: Modify /etc/apt/sources.list
You may choose your favorite text editor, but in this example, I’ll use nano for the process.
sudo nano /etc/apt/sources.list
Original file (may vary):
deb http://deb.debian.org/debian bullseye main deb-src http://deb.debian.org/debian bullseye main deb http://security.debian.org/debian-security bullseye-security main deb-src http://security.debian.org/debian-security bullseye-security main deb http://deb.debian.org/debian bullseye-updates main deb-src http://deb.debian.org/debian bullseye-updates main
deb http://deb.debian.org/debian bookworm main deb-src http://deb.debian.org/debian bookworm main deb http://security.debian.org/debian-security bookworm-security main deb-src http://security.debian.org/debian-security bookworm-security main deb http://deb.debian.org/debian bookworm-updates main deb-src http://deb.debian.org/debian bookworm-updates main
4: Clean and update package lists
Make sure that aptitude has the right packages/versions, without any of the old “stuff”.
sudo apt clean sudo apt update
5: Perform the upgrade
sudo apt upgrade sudo apt full-upgrade
6: Remove old packages
This will remove the old/unrequired packages. Please be sure to review this list to ensure you don’t accidentally delete something you need.
sudo apt autoremove
If you’ve gotten this far, you probably already know what you’re doing and are just looking for a shortcut. I’ve created the following script to make things easier/quicker. I’ve tested this on my installations, but please verify that the sed commands will work in your environment before running them. In the event that there is a problem, the script makes a backup of your sources.list file, which you can restore.
curl https://code.flatironnetworks.com/rfauls/robfauls.com-scripts/raw/branch/main/Linux/Debian/Upgrade/Upgrade-Debian11toDebian12.sh --output debian_upgrade.sh && sh debian_upgrade.sh