Update Ubuntu or Debian without breaking the box

Keeping the system updated patches security holes. It is also how people accidentally reboot into a black screen. Do the boring checks first.

See what you are running

cat /etc/os-release
uname -r

You want the pretty name (Ubuntu 24.04, Debian 12, etc.) and the kernel version. If this is a production server, take a snapshot or backup before a large upgrade.

Refresh the package lists, then upgrade

sudo apt update
apt list --upgradable
sudo apt upgrade

apt update only downloads the catalog. apt upgrade installs newer versions of packages you already have. It will not remove packages to satisfy dependencies. That is usually what you want on a machine that already works.

Use sudo apt full-upgrade (same as dist-upgrade) when upgrade holds packages back and you understand this machine can reboot and can lose a kernel or driver package if the archive requires it. On a desktop, that is often fine. On a remote server, do it from a console you can still reach if SSH dies (provider VNC, IPMI, or a second session).

When you must reboot

ls /var/run/reboot-required 2>/dev/null && echo "reboot needed"

Kernel, glibc, and some driver updates need a reboot. A web browser does not. If the file exists, plan a reboot; do not ignore it for weeks on a server that faces the internet.

If the upgrade errors

  • dpkg was interrupted — run sudo dpkg --configure -a then sudo apt -f install.
  • Held packages — read the names. NVIDIA and third-party repos are the usual culprits. Disable a broken extra repo in /etc/apt/sources.list.d/ rather than forcing with --force.
  • Black screen after reboot — use GRUB’s “Advanced options” and boot the previous kernel. Then see the boot guide.

Do not run random one-line “fix apt” scripts from forums. They often add third-party PPAs you do not need.