Skip to main content
“Could not get lock /var/lib/dpkg/lock-frontend” means another program is installing or updating packages on Ubuntu or Debian right now, and only one may do so at a time. Usually it is the automatic security updates (unattended-upgr) that run shortly after boot. Wait for it to finish, or check what holds the lock with ps aux | grep -E 'apt|dpkg'. Never delete the lock files.

Before you start

  • This error is about APT and dpkg, the package tools of Ubuntu and Debian. AlmaLinux and Rocky use dnf, which waits for its own lock by itself.
  • A lock is a marker a program sets so no second program changes the package database at the same time. Two installs at once can corrupt it.
  • Commands use sudo. As root, leave it out.
Don’t run rm /var/lib/dpkg/lock* or rm /var/lib/apt/lists/lock. Deleting a lock while another install is running can leave half-installed packages and a broken package database. dpkg itself warns that removing the lock file is always wrong.

Cause 1: Automatic updates are running

Ubuntu and Debian install security updates in the background with unattended-upgrades. It runs on a daily timer that also catches up on missed runs at boot, so it is often busy soon after the server starts. The message then names unattended-upgr (the process name is cut to 15 characters) or apt.systemd.daily. Check:
Fix: wait. It usually finishes within a few minutes; a large batch of updates can take longer. To have your command wait instead of failing, use apt (which waits up to two minutes by default) or give apt-get a timeout in seconds:

Cause 2: You are running apt somewhere else

A second SSH session, a tmux or screen window, a control panel or a script may be installing something. Check which process holds the lock:
Fix: go back to that session and let the command finish, or answer its question if it is waiting for input.

Cause 3: An install was interrupted

If a lost SSH connection or a reboot stopped an install halfway, the lock is gone but dpkg reports:
Fix: finish the interrupted work, then repair dependencies:

Cause 4: An apt process is stuck

Only if a process has used no CPU for a long time (for example 30 minutes or more) and isn’t waiting for input should you stop it. Check with ps (Cause 1). If the process is waiting on the network, a broken mirror may be the reason: see apt and dnf repository errors. Fix: stop it gently first, then repair:
Use the PID from your own output. Only use sudo kill -9 1234 if the normal kill has no effect after a minute.

How to check it worked

It should run without any Could not get lock line and end with Reading package lists... Done or a summary of upgradable packages.

Frequently asked questions

Why does this happen every time I log in to a new server?

On first boot the server checks for and installs security updates. Wait five to ten minutes after creating or rebuilding a server before you install software.

Should I turn off unattended upgrades to avoid this?

No. They install security fixes. If you need control over timing, adjust them instead: see enable automatic security updates.

What is the difference between lock and lock-frontend?

lock-frontend is held by the tool you run (apt, apt-get); lock is held by dpkg while it unpacks packages. /var/lib/apt/lists/lock is used by apt update. The fix is the same for all of them.

VPS and dedicated server guides

Every guide in this section.

Update Linux packages

apt and dnf updates done right.

Automatic security updates

Configure unattended-upgrades.

apt and dnf repository errors

Release file, key and mirror errors.

Kill a process

Stop a stuck program safely.

Checked against the Debian dpkg FAQ on database locks and the official Ubuntu package management guide on 4 November 2026; the lock error, dpkg’s warning, apt waiting for the lock and -o DPkg::Lock::Timeout were reproduced on a copy of the package database on Ubuntu 24.04 LTS (apt 2.8.3, dpkg 1.22.6).

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026