Skip to content
Log In Sign Up info@muvcloud.com

What the Error Means

The message reads "Could not get lock /var/lib/dpkg/lock-frontend", often followed by the number and name of the process that holds it, and "Unable to acquire the dpkg frontend lock". Only one program may change installed packages at a time. Another one is running now: usually unattended upgrades, which installs security updates in the background and often starts right after boot, or apt in another terminal. The apt command waits for the lock and shows which process holds it; apt-get stops with the error unless a script tells it to wait. Everything here applies to Debian and Ubuntu.

Find the Process Holding the Lock

ps aux | grep -E 'apt|dpkg'
sudo lsof /var/lib/dpkg/lock-frontend
sudo fuser -v /var/lib/dpkg/lock-frontend

Typical names are unattended-upgr, apt.systemd.daily, apt-get, and dpkg. More on these tools in the lsof command and how to list processes in Linux.

Wait for It to Finish

Automatic updates run from the apt-daily and apt-daily-upgrade timers; the second one starts unattended upgrades. On a newly created server, the first run can take several minutes. Watch its progress:

systemctl list-timers 'apt-daily*'
sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.log

Or let the shell wait and continue on its own:

while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do sleep 5; done
sudo apt install package

See the tail command for following logs.

Why You Should Not Delete the Lock Files

The lock files are /var/lib/dpkg/lock, /var/lib/dpkg/lock-frontend, /var/lib/apt/lists/lock, and /var/cache/apt/archives/lock. The file is not the lock: a running process holds a lock on it, and the system releases that lock when the process exits. Deleting the file while the process runs only lets a second process start writing the package database at the same time. The result can be a damaged package status file and packages that are half installed. If one of them is a core library or the kernel, the server may stop booting. Advice to delete these files is widely copied, and it is the wrong first step.

Why You Should Not Kill dpkg

While dpkg runs, it replaces files and runs install scripts. Killed halfway, it leaves packages unpacked but not configured. If that package is the C library, SSH, or the kernel, logins or the next boot can fail. Wait instead.

If an apt process sits waiting for an answer, such as a configuration question in a forgotten terminal, tmux, or screen session, go back to that session and answer it. Only if an apt process, not dpkg, has clearly hung for a long time with no log activity, stop it with a plain sudo kill and its process number, never with -9, and then repair as below.

Repair After an Interrupted Run

If an earlier run was cut off by a lost SSH connection or a reboot, apt reports that dpkg was interrupted and asks you to run dpkg --configure -a. Take a snapshot first if you can, then:

sudo dpkg --configure -a
sudo apt -f install
sudo apt update
sudo apt upgrade

The first command finishes configuring every unpacked package; the second fixes missing dependencies. Run long package work inside tmux or screen so a dropped connection cannot interrupt it again.

No Process Holds the Lock

Because the lock disappears when its process exits, a lock with no holder is very rare. If lsof and fuser show nothing, read the message again: it is often the "dpkg was interrupted" message, fixed above. If you are still unsure, reboot once while no package process runs.

Prevent It

  • After first boot: give a new server a few minutes before installing software.
  • In scripts: let apt-get wait for the lock with -o DPkg::Lock::Timeout=300.
  • Keep automatic updates on: turning them off removes a security layer; wait for them instead.

The regular update commands are explained in sudo apt update.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations