📖 ~1 min read

Table of contents
  1. Symptom & Impact
  2. Environment & Reproduction
  3. Root Cause Analysis
  4. Quick Triage
  5. Step-by-Step Diagnosis
  6. Solution – Primary Fix
  7. Solution – Alternative Approaches
  8. Verification & Acceptance Criteria
  9. Rollback Plan
  10. Prevention & Hardening
  11. Related Errors & Cross-Refs
  12. References & Further Reading

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.

Illustrative mockup for ubuntu-18-04-lts — ubuntu1804-apt-lock-diagnose.webp
Finding the process holding dpkg or apt locks — Illustrative mockup — Progressive Robot

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.

Illustrative mockup for ubuntu-18-04-lts — ubuntu1804-apt-lock-fix.webp
Safely clearing stale lock state and resuming package operations — Illustrative mockup — Progressive Robot

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.

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.