Fix apt "E: dpkg was interrupted" with dpkg --configure -a
Ubuntu apt "dpkg was interrupted" means an install stopped halfway. Check no other apt runs, finish it with sudo dpkg --configure -a, then rerun the install.
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.An earlier install or upgrade was cut off before it finished (power loss, dropped SSH, Ctrl+C, killed for lack of memory), and dpkg has unfinished work. Until that is done, apt refuses every other install. Make sure no other apt is running, then finish the work with sudo dpkg --configure -a.
[1] Check whether apt or dpkg is running right now. If automatic updates (unattended-upgrades) are in the middle of an install and you treat it as interrupted, you make things worse.
$ ps -eo pid,comm | grep -E 'apt|dpkg|unattended' || echo '(no apt/dpkg process)'(no apt/dpkg process)If a process shows up, wait for it. The error you get in that case is a lock error, not this one — see Fix apt "Could not get lock /var/lib/dpkg/lock-frontend". Do not delete lock files to get past it.
[2] See what was left unfinished. dpkg --audit searches for packages "installed only partially" (man dpkg).
$ sudo dpkg --auditThe following packages are only half configured, probably due to problemsconfiguring them the first time. The configuration should be retried usingdpkg --configure <package> or the configure menu option in dselect: python3.12-minimal Minimal subset of the Python language (version 3.12) The following packages have been triggered, but the trigger processinghas not yet been done. Trigger processing can be requested usingdselect or dpkg --configure --pending (or dpkg --triggers-only): libc-bin GNU C Library: BinariesThese are the packages the interrupted run was working on. If boot-critical packages such as the kernel, libc, or systemd appear, do not reboot until step 3 is done.
[3] Finish the configuration. With -a, "all unpacked but unconfigured packages are configured."
$ sudo dpkg --configure -aSetting up python3.12-minimal (3.12.3-1ubuntu0.17) ...Processing triggers for libc-bin (2.39-0ubuntu8.9) ...If it asks about a configuration file, read the question and answer it. When it finishes, dpkg --audit should print nothing:
$ sudo dpkg --audit$ echo $?0[4] Fix dependencies and repeat the install you were doing. --configure -a only finishes packages already unpacked; packages the interrupted run had not downloaded or unpacked yet are not installed.
$ sudo apt-get -f installBuilding dependency tree...Reading state information...The following packages were automatically installed and are no longer required: libexpat1 libpython3.12-minimal python3.12-minimalUse 'apt autoremove' to remove them.0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.-f (--fix-broken) fills in broken dependencies. Here there was nothing to fix, so it ended with 0 newly installed, and it marked the dependencies unpacked before the interruption (python3.12-minimal and others) as "no longer required". That means the python3 you originally asked for never got installed. Do not run apt autoremove here; repeat the original install instead:
$ sudo apt-get install python3In this test, apt was confirmed working again by installing another package (nano) with exit code 0 after the recovery; reinstalling python3 itself was not run. If an upgrade was interrupted, run sudo apt upgrade again to bring the remaining packages up.
[5] If --configure -a fails on a specific package, read that package's error lines. When you see that its post-installation script failed, the real cause is in the lines above it (disk space, a config file syntax error, a service that would not start, and so on). If it is disk space, free some with Find what is using the space when a disk is full and repeat step 3.