apt: “Could not get lock /var/lib/dpkg/lock-frontend”
Server setup troubleshooting
Updated
What you see
Installing a package on a Debian or Ubuntu server fails with:
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (unattended-upgr) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
What it means
The package manager allows one operation at a time and keeps a lock file while it works. Another program is currently installing or updating — very often the system's own automatic updates, which start the moment a new server boots.
Quick fix
Wait a few minutes and run the command again. See what is holding the lock with ps aux | grep -E 'apt|dpkg'; don't delete the lock file while that process is still running.
Causes and how to fix them
1. Automatic updates are running after first boot
New cloud images check for and install security updates when they first start, which can take several minutes on a small server. See which process holds the lock:
ps aux | grep -E 'apt|dpkg|unattended' sudo lsof /var/lib/dpkg/lock-frontend
2. Another terminal or script is using apt
A second SSH session, an install script or a control panel's installer might be running apt. Let it finish — or close it if you started it by mistake.
3. A previous apt run was interrupted
If nothing is running and the error stays after a restart, an earlier install may have been cut off. Let dpkg finish it:
sudo dpkg --configure -a
Only remove the lock files by hand when you are certain no apt or dpkg process exists. Removing them while one runs can corrupt the package database.
Using Nullsify?
If Nullsify's setup needs to install iptables and the package manager is busy with a new server's first-boot updates, it retries for about a minute before carrying on. If adding a server fails right after you created it, wait a few minutes for the updates to finish and add it again.
Free for 1 server. Bring your own VPS — Nullsify configures WireGuard, AmneziaWG or VLESS on it for you.
Related problems
- “Connection refused” Server setup
- “Operation not supported” WireGuard
- “Permission denied (publickey)” Server setup