Updating Debian

By David Chen @TheEgghead27

Debian, despite its reputation for never updating, regularly releases new releases, and because it is so stable, updating is super simple, barely an inconvenience!

Checking the thing

First, let's take a gander at what version of Debian we have installed.

Sure, you could run neofetch, but if you don't have neofetch installed, or are wondering where neofetch gets its information, check /etc/os-release!

root@debian:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

The contents of this file vary depending on the distro you use, and what release you're using.

You should also run apt update and apt upgrade to install any bug-fixes you might have missed laterly.

Doing the thing!

To update Debian versions, you need to tell apt to get its packages from the latest repositories.

This is configured via /etc/apt/sources.list (custom package sources go into sources.list.d/).

It should look something like this:

root@debian:/etc/apt# cat sources.list
# Generated by distrobuilder
deb http://deb.debian.org/debian buster main
deb http://deb.debian.org/debian buster-updates main

deb http://deb.debian.org/debian-security/ buster/updates main

If you wish, consider backing up the current sources.list by copying it elsewhere, such as to sources.list.bak.

root@debian:~# cd /etc/apt/
root@debian:/etc/apt# ls
apt.conf.d  auth.conf.d  preferences.d  sources.list  sources.list.d  trusted.gpg.d
root@debian:/etc/apt# cp sources.list sources.list.bak
root@debian:/etc/apt# ls
apt.conf.d   preferences.d  sources.list.bak  trusted.gpg.d auth.conf.d  sources.list   sources.list.d

We are now ready to update the package sources to the latest release (or even to the unstable "Sid" branch!)

Edit sources.list to replace all mentions of your current version (in this case, buster) with the version you want to update to (ideally only the next version, in this case bullseye).

If you are already on the latest (as of writing, bullseye), or the second-to-latest (as of writing, buster) version of Debian, it is also safe to use the stable keyword, which will automatically resolve to the latest stable release of Debian (currently bullseye, but will update whenever they release a new one).

If you are on the latest Debian (bullseye), and you want to test out the latest and greatest Debian packages (at the cost of potential bugs - though Debian is still very good at avoiding breakages), you can upgrade to testing, or even unstable ("sid").

Here, we will update to the latest stable Debian by replacing buster with stable. Note that we have to also change buster/updates with stable-security/updates due to a naming change between Debian 10 (buster) and 11 (bullseye).

root@debian:/etc/apt# sed -i "s|buster/updates|stable-security/updates|;s/buster/stable/" /etc/apt/sources.list
root@debian:/etc/apt# cat sources.list
# Generated by distrobuilder
deb http://deb.debian.org/debian stable main
deb http://deb.debian.org/debian stable-updates main

deb http://deb.debian.org/debian-security/ stable/updates main

We are using sed (stream edit) -i(n place, meaning editing the same file you read) to "s(ubstitute) buster/updates for stable-security/updates (using | as the separator to prevent issues with the /); and then another substitution buster for stable (using the traditional / separator)", we can make this change very quickly. This acts similarly to the find-and-replace feature in many text editors.

Run apt update to sync with your updated package sources, and apt upgrade to upgrade your system.

root@debian:~# apt update
Hit:1 http://deb.debian.org/debian stable InRelease
Hit:2 http://deb.debian.org/debian stable-updates InRelease
Get:3 http://deb.debian.org/debian-security stable-security/updates InRelease [48.4 kB]
Get:4 http://deb.debian.org/debian-security stable-security/updates/main amd64 Packages [236 kB]
Get:5 http://deb.debian.org/debian-security stable-security/updates/main Translation-en [154 kB]
Fetched 438 kB in 2s (267 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
133 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@debian:~# apt upgrade -y  # to automatically agree to updates - you may want to read them carefully, but we will skip that for now

You may be asked to restart services, in general, you should tap yes or OK, as it is generally safe to do even when you are upgrading over an SSH connection.

If you are asked about configuration files, it is usually safer to keep your own so you do not lose your configuration.

Once you are done, just reboot, and you've installed the updates!

root@debian:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@debian:~# neofetch
       _,met$$$$$gg.          root@debian
    ,g$$$$$$$$$$$$$$$P.       -----------
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 11 (bullseye) x86_64
 ,$$P'              `$$$.     Host: Compute Instance
',$$P       ,ggs.     `$$b:   Kernel: 6.2.2-arch1-1
`d$$'     ,$P"'   .    $$$    Uptime: 18 mins
 $$P      d$'     ,    $$P    Packages: 236 (dpkg)
 $$:      $$.   -    ,d$$'    Shell: bash 5.1.4
 $$;      Y$b._   _,d$P'      Resolution: 1280x800
 Y$$.    `.`"Y$$$$P"'         CPU: AMD EPYC 7601 (1) @ 2.199GHz
 `$$b      "-.__              Memory: 62MiB / 965MiB
  `Y$$
   `Y$$.
     `$$b.
       `Y$$b.
          `"Y$b._
              `"""

go home