apt "E: Sub-process /usr/bin/dpkg returned an error code (1)": find the package that failed
Fix apt "Sub-process /usr/bin/dpkg returned an error code (1)": find the failing package, read its script error, fix file conflicts, and finish with dpkg --configure -a.
by OhSudo ·
Checked on real software: Ubuntu 24.04, apt, dpkg · November 2026How we check
Errors were encountered while processing: mysql-server-8.0E: Sub-process /usr/bin/dpkg returned an error code (1)This last line only says that dpkg, the program apt uses to install packages, failed. It’s the same line whatever went wrong. The reason is a few lines above it, and the package named under Errors were encountered while processing is where to look.
TL;DR
# 1. The real error: scroll up, or read the loggrep -B2 -A3 'error processing' /var/log/apt/term.log | tail -n 20
# 2. Fix what it says, then let dpkg finish its worksudo dpkg --configure -asudo apt-get install -f1. Find the line that matters
Run the command again, or read /var/log/apt/term.log, which keeps the full output. Look for dpkg: error processing. It comes in two kinds:
dpkg: error processing package mysql-server-8.0 (--configure): installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1dpkg: error processing archive /var/cache/apt/archives/tool_2.1_amd64.deb (--unpack): trying to overwrite '/usr/bin/tool', which is also in package tool-legacy 1.0With dpkg -i instead of apt, the second one says (--install). The first is a script that failed while setting the package up (section 2). The second is a file conflict between two packages (section 3). A full disk shows up here too, as No space left on device.
2. A package script failed
Packages run scripts while being installed or removed: preinst, postinst, prerm and postrm. A post-installation script that returned error exit status 1 most often failed to start the program’s service. The lines just above it say why:
Job for mysql.service failed because the control process exited with error code.See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.invoke-rc.d: initscript mysql, action "start" failed.Then it’s a service problem, and Job for service failed shows how to read its log. Common reasons are a port already in use, a broken configuration file left from an earlier install, or too little memory. Fix that, and run the step again:
sudo dpkg --configure -aTo see what the script does, it’s in /var/lib/dpkg/info/:
less /var/lib/dpkg/info/mysql-server-8.0.postinstIf you don’t need the package, remove it instead. When even removal fails because of its own script, --force-remove-reinstreq removes it without running that script:
sudo apt-get remove --purge mysql-server-8.0sudo dpkg --remove --force-remove-reinstreq mysql-server-8.0 # only if the line above fails3. Two packages want the same file
trying to overwrite …, which is also in package … means two packages ship the same file, often one from Ubuntu and one from a third-party repository or a .deb you downloaded. Usually one replaces the other, so remove the old one first:
sudo apt-get remove tool-legacysudo apt-get install -fIf you’re sure the new package should win, you can install that one archive and overwrite the file:
sudo dpkg -i --force-overwrite /var/cache/apt/archives/tool_2.1_amd64.debsudo apt-get install -fMixing repositories for different releases (an old PPA, a Debian repository on Ubuntu) is the usual cause, so check /etc/apt/sources.list.d/ as well.
4. Other reasons
- Disk full:
df -h /anddf -h /boot. A full/bootis common with old kernels. See No space left on device. - An earlier install was interrupted: dpkg was interrupted is the same
dpkg --configure -afix. - Another apt is running: that’s Could not get lock, not this error.
- Broken dependencies:
sudo apt-get install -finstalls what’s missing, or tells you which package to remove.
/var/log/dpkg.log lists, with times, every package’s state changes, which helps when several failed.
Warning
Don’t edit or delete files in /var/lib/dpkg/ to make the error go away, beyond reading a package’s script. That folder is dpkg’s database of what’s installed, and a damaged one breaks every later install. Fix the cause, then let dpkg --configure -a finish.
Shell, we have a problem!
Similar, but different: E: Unable to locate package means apt can’t find the package at all. NO_PUBKEY means a repository’s key is missing. Could not get lock means another install is running. On Fedora or Rocky, a failed scriptlet shows up as error: %post(package) scriptlet failed, exit status 1.
Found this useful? Share it.
Found a mistake? Let us know at contact@ohsudo.com.