0

I recently ran into some dpkg errors will running sudo apt full-upgrade on my VM (I ran update beforehand). I don't have the error message handy, but I remember it saying dpkg returned an error code of 1. I noticed from some of the output that apt/dpkg looked like it was removing packages that were dependencies of other packages, and it said "but removing anyway as you requested". Afterwards, nothing worked. dpkg threw more errors when I tried to run a command, Firefox crashed, the VM wouldn't shutdown. Luckily I take backups before I do upgrades. My questions came up when I was researching how to fix this.

  1. What is the difference between sudo apt full-upgrade and sudo apt upgrade? I read the man pages and understand the conceptual difference. What I don't get is when you'd use one over the other. What are the consequences of removing old packages like full-upgrade does, or not removing them like upgrade does? I assume everything broke because thefull-upgrade removed packages that were still being used.
  2. Whats the difference between -fix--missing and -fix--broken? Again, I read the man pages, but I don't get when you use one over the other, or what the consequences of each are. I couldn't find a lot online about the difference between a broken or a missing package.
  3. How does using -f with apt install differ from using it with apt update? I think I know what will happen, but I don't understand it.

Finally, most guides for fixing packages issues with apt contained some version of the following:

  1. Open the terminal and enter: sudo apt --fix-missing update
  2. Update your system's package list from the available sources: sudo apt update
  3. Now, force the installation of the broken packages using the -f flag. APT will automatically search for broken packages on your system and reinstall them from the official repository: sudo apt install -f.

If the aforementioned steps do not work for you, you can try to solve the issue using dpkg.

  1. Force dpkg to reconfigure all the pending packages that are already unpacked but need to undergo configuration. The -a flag in the following command stands for All*: sudo dpkg --configure -a*
  2. Pipe grep with dpkg to get a list of all the packages marked as Required*: sudo dpkg -l | grep ^..r*
  3. Use the --remove flag to delete all the broken packages: sudo dpkg --remove --force-remove-reinstreq
  4. Clean up the package cache and install scripts using apt clean*: sudo apt clean*
  5. Now, update your system's package lists using the following command: sudo apt update

I couldn't find many guides that fully explained why you run each step. I sort of get the picture, but I think I need someone to tie it together for me. I feel like whenever I get errors from apt/dpkg I sort of freak out and ignore them, or frantically copy and paste random commands I find after googling the problem hoping something works. I'm trying to be more intelligent about solving it this time.

1 Answer 1

2
  1. In regular use, for day-to-day upgrades in a stable release, you should only need to use apt upgrade, not apt full-upgrade. The latter is important when upgraded packages conflict with older packages, and the older packages need to be removed to complete the upgrade; this is only supposed to happen when upgrading between stable releases (e.g. Debian 11 to Debian 12) or when running an in-development release. However apt full-upgrade should be safe to use anyway, at least as long as you check the list of changes apt tells you it’s going to make before letting it go ahead.

    It’s unlikely that your system breakage is related to apt full-upgrade. Given the output you saw, it’s likely your VM hadn’t been upgraded for a while, and that the upgrade was significant. In such scenarios, it’s normal for packages to be removed during the upgrade, and for dpkg to complain — that’s because apt splits operations up, and has to force dpkg in some instances. The important part of your upgrade is the error leading up to dpkg exiting with an error code.

  2. --fix-missing is slightly misleading; it is synonymous with --ignore-missing which is more descriptive. It instructs apt install (not apt update) to ignore packages it can’t download, and skip the corresponding installation or upgrade.

    --fix-broken instructs apt to resolve broken dependencies.

  3. -f (--fix-broken) is meaningless with apt update. apt update only updates local copies of package repository indexes, it doesn’t touch individual packages.

Many guides on the Internet are misguided, and the one you’ve found is a good example:

  • apt --fix-missing update is equivalent to apt update, --fix-missing has no effect there.

  • The description of sudo dpkg -l | grep ^..r (which doesn’t need sudo) is incomplete: that command lists packages marked as requiring reinstallation.

  • With the above fix, the next command makes more sense, but it’s incomplete: the list of packages to remove needs to be specified. But that’s not the correct fix; packages requiring reinstallation should be reinstalled (sudo apt reinstall …), not removed.

  • apt update at the end is useless.

The best thing to do with apt/dpkg errors is to slow down, read them carefully, and if they don’t make sense, look them up specifically on the Internet. I don’t have a good recipe to determine whether information you’ll find that way is trustworthy or not; if in doubt you can always ask on one of your distribution’s support channels or here. It’s also worth taking the time to read your distribution’s documentation (before you end up in a panic).

3
  • Wow what a fantastic answer! A few follow up questions: Kind of a stupid one, but when you check the list of changes apt tells you it’s going to make, how do you know which changes should be made and which could cause issues? Also, I try to upgrade the VM once a month, so it should be up to date. So --fix-missing and -f only work with apt install and not apt update correct? How exactly does apt go about resolving broken dependencies (man pages never really explained)? What's the point of using dpkg configure? From your comments, it sounds like those steps 1-5 aren't advisable to run.
    – Matt
    Commented Jun 25 at 1:02
  • The main tip-off that things are going wrong is when apt tells you it’s going to remove lots of packages, particularly meta-packages such as gnome or gnome-core. --fix-missing and --fix-broken only work with apt install (or apt remove), yes; I thought that was clear in my answer but apparently not ;-). I don’t really have room to explain how the apt resolver works here... dpkg --configure asks dpkg to complete package setup; in many cases, if apt is interrupted or while installing packages, some are left in an incomplete state, --configure fixes that. Commented Jun 29 at 9:48
  • Thanks for clarifying! I'll try to do some more digging on my end. Thanks again for the great answer!
    – Matt
    Commented Jun 30 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .