📖 ~1 min read
Table of contents
Symptom & Impact
apt or apt-get exits with Could not get lock /var/lib/dpkg/lock-frontend, blocking installs and updates.
Environment & Reproduction
Ubuntu 18.04 LTS hosts where unattended-upgrades, aptd, or another package task is active. Running sudo apt update or sudo apt install reproduces the error.
Root Cause Analysis
A legitimate package process is still running or a previous apt/dpkg run terminated unexpectedly and left lock metadata behind.
Quick Triage
Run ps aux | grep -E ‘apt|dpkg|unattended’ and sudo lsof /var/lib/dpkg/lock-frontend to confirm owner process before touching lock files.
Step-by-Step Diagnosis
Check systemd timers and apt history with systemctl status apt-daily.service apt-daily-upgrade.service and tail /var/log/apt/history.log.

Solution – Primary Fix
If a real process exists, wait or stop it cleanly, then run sudo dpkg –configure -a and sudo apt -f install. Remove stale locks only when no apt/dpkg process is active.
Still having issues? Our IT Solutions & Services team can diagnose and resolve this for you. Get in touch for a free consultation.

Solution – Alternative Approaches
Temporarily disable apt-daily timers during maintenance windows using systemctl stop/disable –now apt-daily.timer apt-daily-upgrade.timer, then re-enable afterward.
Verification & Acceptance Criteria
sudo apt update and sudo apt upgrade complete without lock errors, and dpkg reports no half-configured packages.
Rollback Plan
Re-enable stopped timers and restore previous package state from backups or snapshots if package consistency is not recoverable.
Prevention & Hardening
Schedule maintenance windows, avoid parallel apt sessions, and monitor unattended-upgrades logs for long-running jobs.
Related Errors & Cross-Refs
dpkg was interrupted, E: Sub-process /usr/bin/dpkg returned an error code, and failed unattended-upgrades units.
Related tutorial: View the step-by-step tutorial for Ubuntu 18.04 LTS.
View all Ubuntu 18.04 LTS tutorials on the Tutorials Hub →
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
man apt, man dpkg, Ubuntu Server Guide package management, and journalctl -u apt-daily.service.
Need Expert Help?
If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today — we respond within one business day.