Stackrig

Home Blog

tested run on a fresh Ubuntu 24.04, 7 October 2026 Run on Ubuntu 24.04 published

Could not get lock /var/lib/dpkg/lock-frontend on Ubuntu 24.04

We earn commissions when you shop through the links below.

We started a second apt while a first one was installing on a fresh Ubuntu 24.04: it named who held the lock, waited, and went on by itself.

Short answer: wait. On 7 October 2026, on a fresh Ubuntu 24.04 with apt 2.8.3, we ran sudo apt install tree while another apt was still installing. It printed Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2128 (apt), counted the seconds, and after 33 of them went on by itself and installed the package. The line names the process that holds the lock, and ps -C apt -o pid,etime,args shows what that process is. We deleted no lock file and ended no process.

What this was run on, and what it does not cover

We ran every command on this page on a fresh virtual machine at a cloud provider, started from Ubuntu's official 24.04 server image, where a script ran the commands and kept everything the machine printed. A block marked Output shows what the command above it printed, or the lines of it that matter, and a line is always shown whole.

date -u +%Y-%m-%d
lsb_release -a
whoami
apt --version
2026-10-07
Description:	Ubuntu 24.04.5 LTS
ubuntu
apt 2.8.3 (amd64)

That is one release of Ubuntu, one machine, one day and one architecture, x86_64. Before anything else the script fetched the package lists; this is the last line that command printed.

sudo apt update
33 packages can be upgraded. Run 'apt list --upgradable' to see them.

This page covers one cause: a second apt started while a first one is at work. It doesn't cover a lock left behind by an apt or dpkg that was interrupted, the automatic updates of a new machine, removing a lock file, or ending a process.

Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2128 (apt)

To make this line, one apt has to be at work when a second one starts. A reader has the first in another terminal. Our script has a single line of commands, so it put the first install in the background and sent what it prints to a file, with -y because nobody can answer apt's question there.

sudo apt install -y default-jdk > first-apt.log 2>&1 &

Then the script waited until the lock was held: timeout 60 bash -c "until sudo lslocks | grep -q lock-frontend; do sleep 1; done". Before the second apt, two looks at the first: the locks of dpkg with who holds them, and the apt that is at work, with its process number, how long it has run, and its command.

sudo lslocks | grep dpkg
apt              2128 POSIX      WRITE 0     0   0 /var/lib/dpkg/lock-frontend
apt              2128 POSIX      WRITE 0     0   0 /var/lib/dpkg/lock
ps -C apt -o pid,etime,args
    PID     ELAPSED COMMAND
   2128       00:00 apt install -y default-jdk

Now the second apt. It ran at a terminal, where it drew one line again and again, once a second with the seconds it had waited at its end and in between without them. This is the line without the seconds.

sudo apt install tree
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2128 (apt)

The seconds went from 0 to 33. Then the line was gone, replaced by apt's usual lines, and the install went on without anything typed.

The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 33 not upgraded.

Why apt waits

The line says who holds the lock: process 2128, an apt. That is the number both looks printed before the second apt started. The first look says that this apt holds /var/lib/dpkg/lock-frontend, and the second that it is the install of default-jdk. dpkg's manual has a name for what apt is here, "a package manager frontend", and speaks of "the frontend lock" (dpkg(1), under DPKG_FRONTEND_LOCKED). The first apt held that file's lock while it worked, and the second waited for it.

The fix: wait, and look who holds the lock

The second apt needed nothing from us. When it had ended, no apt was at work any more: the same look printed its heading and no process.

ps -C apt -o pid,etime,args
    PID     ELAPSED COMMAND

Both packages were installed, the first apt's and the second's.

dpkg-query -W default-jdk tree
default-jdk	2:1.21-75+exp1
tree	2.1.1-2ubuntu3.24.04.2

The same command again, with nobody holding the lock, printed no waiting line.

sudo apt install tree
tree is already the newest version (2.1.1-2ubuntu3.24.04.2).
0 upgraded, 0 newly installed, 0 to remove and 33 not upgraded.

We deleted no lock file and ended no process. The first apt finished its work, and that was all the second one needed.

The app is free to try in your browser, without an account. To hear when Pro is ready, join the waitlist.

Sources

  • Our own run: a script on a fresh Ubuntu 24.04 machine on 7 October 2026. Every command and every output on this page is from the script and its log.
  • Ubuntu 24.04's manual page dpkg(1), under DPKG_FRONTEND_LOCKED: the frontend lock and who takes it.

Stackrig