Operations 4 min read

How to Resolve “Could not get lock /var/lib/dpkg/lock” Errors on Ubuntu

This guide explains why apt lock errors occur, how to identify the process holding the lock, and step‑by‑step commands to safely release or remove the lock files and restore normal package management.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Resolve “Could not get lock /var/lib/dpkg/lock” Errors on Ubuntu

When using the apt package manager on Ubuntu, you may encounter errors such as:

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

These messages indicate that another process is currently performing an apt operation, which locks the package database and prevents concurrent actions.

Typical Solutions

In most cases you can simply wait a few minutes for the other operation to finish; the lock will be released automatically. If the lock persists, you need to identify and terminate the offending process, then remove the lock files.

Identify the locking process

$ sudo lsof /var/lib/dpkg/lock

Similar commands for other lock files:

$ sudo lsof /var/lib/dpkg/lock-frontend
$ sudo lsof /var/lib/apt/lists/lock

The output shows the PID of the process, e.g.:

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
unattende 1548 root   6uW  REG  8,2   0      1181062 /var/lib/dpkg/lock

Terminate the process

$ sudo kill -9 1548

Remove the lock files

$ sudo rm /var/lib/dpkg/lock
$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo rm /var/lib/apt/lists/lock
# optional cache lock
$ sudo rm /var/cache/apt/archives/lock

Finish pending configuration

$ sudo dpkg --configure -a

After these steps, apt should work normally again.

Remember to only force‑kill processes and delete lock files when you are sure no legitimate package operation is running, as interrupting an active installation can leave the system in an inconsistent state.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem AdministrationLockAPTpackage managementdpkg
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.