SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
System New Added 8 September 2026

apt: Could not get lock /var/lib/dpkg/lock-frontend

Another process holds the package manager lock. On a freshly booted Ubuntu machine it is nearly always unattended-upgrades running in the background, which is why cloud-init scripts and CI jobs hit it in the first minutes of a VM's life.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# Who has it?
sudo lsof /var/lib/dpkg/lock-frontend
sudo systemctl status unattended-upgrades

# Usually the right answer is to wait for it
sudo systemd-run --property=After=apt-daily.service --wait /bin/true

# Scripted installs: wait rather than racing
while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do sleep 5; done
sudo apt-get install -y curl

# Only if no process holds it and dpkg was interrupted
sudo rm /var/lib/dpkg/lock-frontend && sudo dpkg --configure -a

How to diagnose System errors

System-level errors are usually a resource limit being hit: disk, inodes, file descriptors, memory or process count. Two traps recur. "No space left on device" can mean inodes are exhausted while df -h shows free space. And a process that vanished without an error in its own log was almost certainly killed by the OOM killer, which logs to the kernel ring buffer rather than to the application.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Check both space and inodes: df -h and df -i. Millions of tiny files exhaust inodes long before bytes.
  2. For processes that disappear, search the kernel log: dmesg -T | grep -i -E 'oom|killed process' or journalctl -k.
  3. For systemd units, systemctl status unit then journalctl -u unit -n 200 --no-pager. The status output truncates the useful part.
  4. For "too many open files", check both the limit and the usage: ulimit -n, cat /proc/<pid>/limits, and ls /proc/<pid>/fd | wc -l. systemd services need LimitNOFILE, not a shell ulimit.
  5. For cron jobs that work manually but not scheduled, remember cron has a minimal environment and no PATH. Use absolute paths and log stdout and stderr to a file.

Tools worth reaching for

  • df -h / df -i
  • dmesg -T
  • journalctl -u
  • lsof / ss
  • systemd-analyze blame
  • ncdu

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

manpages.ubuntu.com

Related System errors

See all 26 System errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.