📖 ~1 min read
Table of contents
Symptom & Impact
Running apt or apt-get fails with lock errors such as /var/lib/dpkg/lock-frontend. Security updates and package installs are blocked until the lock is released.
Environment & Reproduction
Ubuntu 22.04 LTS servers or desktops where unattended-upgrades, snap refresh, or another apt process runs in parallel. Reproduce by opening two terminals and launching apt update concurrently.
Root Cause Analysis
dpkg permits a single writer to package databases. A second package tool sees active lock files; stale locks may remain after abrupt shutdowns.
Quick Triage
Check active package tasks first: ps aux | egrep ‘apt|dpkg|unattended’. If a process is active, wait for completion and re-run apt update.
Step-by-Step Diagnosis
Identify lock holders with sudo lsof /var/lib/dpkg/lock-frontend /var/cache/apt/archives/lock. Review apt history in /var/log/apt/history.log and journalctl -u unattended-upgrades.

Solution – Primary Fix
If no process owns the lock, remove stale lock files and repair package state: sudo rm -f /var/lib/dpkg/lock-frontend /var/cache/apt/archives/lock && sudo dpkg –configure -a && sudo apt -f install.
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
Disable conflicting timers briefly: sudo systemctl stop apt-daily.timer apt-daily-upgrade.timer, run maintenance, then re-enable timers.
Verification & Acceptance Criteria
apt update and apt upgrade run without lock errors, dpkg –audit returns clean output, and unattended-upgrades resumes normally.
Rollback Plan
Restore timer state and package lists from backups if required. If package database corruption appears, recover from VM snapshot or filesystem backup.
Prevention & Hardening
Avoid concurrent package sessions, schedule maintenance windows, and keep unattended-upgrades enabled with predictable timing.
Related Errors & Cross-Refs
Could not get lock /var/lib/dpkg/lock-frontend, dpkg was interrupted, E: Sub-process /usr/bin/dpkg returned an error code.
Related tutorial: View the step-by-step tutorial for Ubuntu 22.04 LTS.
View all Ubuntu 22.04 LTS tutorials on the Tutorials Hub →
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
Ubuntu Packaging Guide, man apt, man dpkg, Ubuntu unattended-upgrades documentation.
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.