Upgrade Debian To The Newest Release
26 April 2023 2023-07-15 15:16Upgrade Debian To The Newest Release
Preparing For The Upgrade
Debian 9 Or Older
Upgrading directly from releases that are older than 10 (buster) are not supported. Follow the instructions in the release notes to upgrade to 10 first.
To display your Debian version, run this command:
$ cat /etc/debian_version
Back Up Any Data And Configurations
Before upgrading your system, it is strongly recommended that you make a full backup. Alternatively, at minimum back up any data or configuration information that you can’t afford to lose. Otherwise there might be areas where you will have to reconfigure your system. The upgrade process is quite good, but a hardware failure in the middle of the process could result in a badly damaged system.
The upgrade process itself does not modify anything in the /home directory. Regardless, some applications (e.g. parts of the Mozilla suite, and the GNOME and KDE desktop environments) are known to overwrite existing user settings with new defaults when a new version of the application is first started. As a precaution, consider backing up the hidden files and directories (“dotfiles”) in the users’ home directories. This backup may help to restore or recreate the old settings.
Preconditions
The upgrade has a few preconditions; you should check them before actually executing the upgrade. Make sure you have enough disk space for the upgrade to complete. Also, any package installation operation must be run with superuser privileges. Switch to root by using this command:
$ su -
Install all updates for your current system:
# apt update && apt upgrade
Remove unnecessary packages. Manually uninstall programs you know you are not using. Run this command to let apt remove leftover packages.
# apt autoremove
Check the status of all packages and verify that they are in an upgradable state. Run this command:
# dpkg --audit
If you changed packages, and didn’t rename it or put an epoch in the version then you must put it on hold to prevent it from upgrading. For apt the package state “hold” can be changed using:
# echo package_name hold | dpkg --set-selections
Replace hold with install to undo the “hold” state.
Prepare The APT source-list File
Edit the source-list file to add the sources for the latest Debian release, which at this time is bullseye, and remove sources for older releases.
# nano /etc/apt/sources.list
To use the Debian APT CDN service, add the following lines. These add the main repository and the security repository.
deb http://deb.debian.org/debian/ bullseye main contrib non-free deb-src http://deb.debian.org/debian/ bullseye main contrib non-free deb http://security.debian.org/debian-security bullseye-security main contrib non-free deb-src http://security.debian.org/debian-security bullseye-security main contrib non-free
Make sure to change any other repositories you may be using so that they use the packages for bullseye. Remember to save before exiting the file.
Upgrading Packages
Update apt:
# apt update
Clean up your system:
# apt autoremove # apt autoclean
Upgrade the packages:
# apt upgrade
During the upgrade you will be prompted whether you want to keep the current version of GRUB. Select the option you prefer. Recommended is to update GRUB as well. You might also be prompted to keep configuration files or to overwrite them with the ones that come in the new packages. Compare the files and decide on what to do. Sometimes it is safe to overwrite, other times you might want to reconfigure the file after the upgrade is completed.
Upgrade The System
To do the main upgrade of the system, run:
# apt dist-upgrade
Once the upgrade is finished, reboot the system.
Clean The System
Remove new redundant or obsolete packages. Run:
# apt autoremove # apt autoclean
Purge removed packages. To display a list of all removed packages that may have configurations left on the system, run:
# dpkg -l | awk '/^rc/ { print $2 }'
To purge all of them in one go, run:
# apt purge $(dpkg -l | awk '/^rc/ { print $2 }')
That’s it. The system is now upgraded to the latest release. Make sure to check the configurations of your programs to see if you have to reconfigure some settings.