Linux Error Guide: 'dpkg: error processing package' — Repair Half-Configured Packages
Fix 'dpkg: error processing package' and 'E: Sub-process /usr/bin/dpkg returned an error code (1)' on Debian/Ubuntu: repair half-configured packages, broken deps, and failing postinst scripts.
- #linux
- #troubleshooting
- #errors
- #apt
Stuck on this Linux Admins error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
Overview
When a package’s configuration step fails, dpkg reports the specific package and then apt bubbles up a generic sub-process failure:
Setting up myservice (2.4.1-1) ...
Job for myservice.service failed because the control process exited with error code.
dpkg: error processing package myservice (--configure):
installed myservice package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
myservice
E: Sub-process /usr/bin/dpkg returned an error code (1)
The package is now left half-configured (iF state): its files are unpacked but its postinst script did not finish, and apt will refuse most further operations until this is resolved.
Symptoms
apt install/apt upgradeends withE: Sub-process /usr/bin/dpkg returned an error code (1).- Every subsequent apt command warns
you have held broken packagesor asks you to runapt --fix-broken install. dpkg -lshows the package in aniF(half-configured) oriU(unpacked) state instead ofii.- The failure names a maintainer script step:
post-installation script subprocess returned error exit status 1. - A service
postinstfailed because the daemon would not start (bad config, port in use, missing directory).
Common Root Causes
- Failing maintainer script — the package’s
postinst/preinstruns a command that exits non-zero, commonly asystemctl startfor a service that cannot start (bad config file, occupied port, missing user). - Unmet or broken dependencies — a dependency failed to configure first, so this package cannot be configured either; the whole chain is stuck.
- Interrupted dpkg — a previous install was killed (power loss,
Ctrl-C, OOM), leaving packages half-installed; often paired withE: dpkg was interrupted. - Disk full during unpack —
postinstcannot write files because the filesystem hitENOSPC. - Conflicting or held packages — a
dpkg --forceinstall or a manual.debcreated a version conflict. - Corrupt dpkg database or leftover files — a diverted/duplicated file makes
dpkg-divertordpkg --configurefail.
Diagnostic Workflow
Read the actual error above the generic apt line — the failing maintainer-script command is the real cause. Then identify every package not in the clean ii state:
sudo apt-get install -f # attempt automatic repair of broken deps
dpkg -l | grep -vE '^ii|^rc' | grep '^.[a-zA-Z]' # packages in bad states
dpkg --audit # packages needing reinstall/configuration
Try to complete the pending configuration and capture the exact failure:
sudo dpkg --configure -a
If a service postinst failed, read why the daemon would not start:
systemctl status myservice --no-pager
journalctl -u myservice -b --no-pager | tail -n 30
Rule out the environmental causes that break configuration:
df -h /var /usr; df -i /var # disk/inode exhaustion during unpack
sudo apt-get update # stale metadata causing dep resolution failures
Example Root Cause Analysis
An apt upgrade fails with dpkg: error processing package postgresql-16 (--configure) and Sub-process /usr/bin/dpkg returned an error code (1). Scrolling up, the real line is Job for postgresql@16-main.service failed. Running journalctl -u postgresql@16-main -b | tail shows could not bind IPv4 address "0.0.0.0": Address already in use — an old, manually started Postgres process was still holding port 5432, so the package’s postinst could not start the new instance and exited non-zero, leaving postgresql-16 half-configured.
The fix was to clear the conflict, then let dpkg finish the configuration it had already staged:
sudo ss -ltnp | grep :5432 # find the stray process
sudo kill <old-pid>
sudo dpkg --configure -a # completes the pending postinst
dpkg --configure -a re-ran the postinst, the service started, and the package moved to ii. The lesson: Sub-process ... error code (1) is only apt’s summary — the useful message is the maintainer-script line above it, and for service packages the root cause is usually in journalctl, not in dpkg.
Prevention Best Practices
- Read the lines above
E: Sub-process ... error code (1); that named package and script line is the actual failure. - Make
sudo dpkg --configure -aandsudo apt-get install -fyour first two repair steps before anything drastic. - Keep
/var(dpkg database, unpack area) with free space and inodes; monitor and alert before it fills. - Never interrupt dpkg mid-transaction; if you must, expect to run
dpkg --configure -aafterward. - Avoid
dpkg -i --force-*on production systems; it is the fastest route to a broken dependency graph. - Run
apt-get updatebefore installs so dependency resolution uses current metadata. - Reserve
--reinstall(and, as a last resort, editing scripts under/var/lib/dpkg/info/) for when configuration cannot otherwise complete.
Quick Command Reference
sudo dpkg --configure -a # finish pending configuration
sudo apt-get install -f # fix broken dependencies
dpkg --audit # packages needing attention
dpkg -l | grep -vE '^ii|^rc' # packages in a bad state
journalctl -u <svc> -b | tail # why a service postinst failed
sudo apt-get install --reinstall <pkg> # re-run a package's install cleanly
df -h /var && df -i /var # rule out full disk / inodes
Conclusion
dpkg: error processing package leaves a package half-configured, and E: Sub-process /usr/bin/dpkg returned an error code (1) is just apt’s summary of it — the real cause is the maintainer-script line printed above, most often a service that would not start or an unmet dependency. Work the standard recovery path: apt-get install -f, then dpkg --configure -a, reading journalctl for any failing service, and check /var for a full disk. Fix the underlying reason the postinst failed and dpkg will complete the configuration it already staged, returning every package to the clean ii state.
Fixed it? Get 500 Linux Admins & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Did this fix your issue?
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4modprobe: FATAL: Module not found
- 5mount: wrong fs type, bad option, bad superblock
- 6Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.