apt: Could Not Get Lock /var/lib/dpkg/lock

apt refuses to install with 'Could not get lock /var/lib/dpkg/lock'. Another package process is already running. Usually you just wait a minute — here's how to confirm that, and what to do if it's truly stuck.

BytExplorer 5 min read July 1, 2026

You run apt install and it won't start:

E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend),
   is another process using it?

This is a safety feature, not a fault. Only one program may change installed packages at a time, so apt/dpkg takes a lock. This error means something else already holds it. On a fresh server that "something" is very often the automatic background updater — and the right move is usually to simply wait.

Cause 1: Automatic updates are running (most common)

New Ubuntu/Debian boxes run unattended-upgrades shortly after boot. It holds the lock while it works. Give it a couple of minutes and try again — it releases the lock when it finishes.

Cause 2: You have another apt open

A second terminal running apt, or a software-updater GUI, holds the lock too. Close the other one and retry.

Step 1: See who holds it

The error prints the PID; confirm what it is before touching anything:

ps -p 1234 -o pid,cmd     # what is process 1234?

If it's apt, dpkg, unattended-upgrade, or packagekitd — that's legitimate. Let it finish.

Resist the urge to delete the lock file immediately. The lock usually means the system is correctly busy; killing it mid-update can leave packages half-configured.

Step 2: Only if it's genuinely stuck

If no package process is actually running and the lock is stale (say, a previous apt was killed), then clear it. Remove the locks and repair any half-done state:

sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock
sudo rm /var/lib/apt/lists/lock
sudo dpkg --configure -a       # finish any interrupted install
sudo apt update

Do this only after confirming with ps that nothing is mid-operation.

The checklist

  1. The lock means another package process is running — often it's fine.
  2. ps -p <pid> -o cmd to see who holds it; if it's apt/unattended-upgrade, wait.
  3. Close any other apt window or updater GUI.
  4. Truly stale? Remove the lock files, then sudo dpkg --configure -a — last resort only.
Put it into practice

Stop reading, start building

This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.

More in Troubleshooting