APT or DPKG is blocked after an interrupted update
An APT lock often means another update is still running. Deleting the lock files right away can corrupt the package database.
An APT lock often means another update is still running. Deleting the lock files right away can corrupt the package database.
Step-by-step procedure
-
Find an active process
Check ps and systemd. Wait if unattended-upgrades or apt is still using the package manager.
-
Finish configuring DPKG
When no apt process is still running, run dpkg --configure -a.
-
Fix dependencies
Run apt-get -f install, then apt update and check each repository error.
-
Restart the update
Update in a persistent session and keep noVNC available in case of SSH outage.
Careful repair
ps aux | grep -E "apt|dpkg"
dpkg --configure -a
apt-get -f install
apt update
See what holds APT and the latest log
systemctl status unattended-upgrades apt-daily.service apt-daily-upgrade.service --no-pager
tail -n 50 /var/log/apt/term.log
dpkg --audit
Update inside a persistent session
apt install -y tmux
tmux new -s upgrade
apt update && apt upgrade
# after an SSH drop: tmux attach -t upgrade
Before you start
Work as root from the "noVNC console" or inside a tmux session: an SSH drop in the middle of an update is the most common cause of an interrupted DPKG. Also check the space with df -h, because a full / interrupts package installation.
- Copy the exact APT message: it names the package and the file involved.
- Never run two package managers at the same time (apt, apt-get, aptitude, unattended-upgrades).
- On Rocky Linux and AlmaLinux, the package manager is dnf: this guide does not apply.
Read the APT message
Each message calls for a different action:
- E: Could not get lock /var/lib/dpkg/lock-frontend: another process is using APT, wait for it to finish.
- E: dpkg was interrupted: an installation was cut off, run dpkg --configure -a.
- E: Unmet dependencies: dependencies are missing, apt --fix-broken install installs them.
- dpkg: error processing package: a package script failed, the lines just above give the reason.
Check that everything works
dpkg --audit must print nothing and apt-get check must finish without errors. Then run apt update and apt upgrade: no lock and no half-installed package should be reported.
Frequently asked questions
The lock is not released although no update is running, can I delete it?
A lock is only active while a process holds it: a lock file left with no process blocks nothing. If the error comes back, a process does exist. When the VPS boots, unattended-upgrades often installs security updates for a few minutes. Let it finish: killing it leaves DPKG interrupted.
apt update shows NO_PUBKEY for a third-party repository, what should I do?
The signing key of this repository is missing or has expired. Reinstall it following the vendor documentation (Docker, Node.js, PHP), or disable the repository by renaming its file in /etc/apt/sources.list.d/ with the .disabled extension, then run apt update again.
What does Sub-process /usr/bin/dpkg returned an error code (1) mean?
This final message is generic. The real cause appears higher up or in /var/log/apt/term.log: often a service that refuses to restart after the update (read systemctl status followed by its name), a configuration file edited by hand or a full disk.