How to Fix APT and dpkg Lock Errors on Ubuntu and Debian

When you install or update packages on Ubuntu or Debian, you may see an error saying that APT or dpkg could not obtain a lock:
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2481 (apt)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?The lock prevents two package managers from changing the package database at the same time. In most cases, another update is still running and the correct fix is to let it finish. If the process is stuck, you need to identify and stop it before repairing the package state.
This guide explains how to resolve APT and dpkg lock errors without deleting lock files or damaging the package database.
Quick Reference
For a printable quick reference, see the apt cheatsheet .
| Task | Command |
|---|---|
| Show the process from the error | ps -p PID -o pid,etime,cmd |
| Check APT lock holders | sudo lsof /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock /var/lib/apt/lists/lock |
| Check with fuser | sudo fuser -v /var/lib/dpkg/lock-frontend |
| Check automatic update services | systemctl status apt-daily.service apt-daily-upgrade.service unattended-upgrades.service |
| Ask a stuck process to stop | sudo kill PID |
| Finish pending package configuration | sudo dpkg --configure -a |
| Repair broken dependencies | sudo apt --fix-broken install |
| Refresh the package index | sudo apt update |
Why the Lock Error Occurs
APT and dpkg use lock files to coordinate access to package data. A lock error commonly appears when:
- Another terminal is running
apt,apt-get,dpkg, or a graphical software manager. - Ubuntu’s automatic update services are checking for or installing updates.
- A package operation was interrupted and left a process running.
- A package manager process stopped responding.
The error often includes the process ID that holds the lock. That PID is the safest place to start because it tells you which process currently owns package management.
/var/lib/dpkg/lock, /var/lib/dpkg/lock-frontend, /var/cache/apt/archives/lock, or /var/lib/apt/lists/lock as a first response. Removing a lock file does not stop the process using the package database, and two concurrent writers can leave packages in an inconsistent state.Step 1: Check the Process Holding the Lock
Replace 2481 with the PID shown in your error:
ps -p 2481 -o pid,etime,cmd PID ELAPSED CMD
2481 01:42 apt upgradeThe ELAPSED column shows how long the process has been running. If it is an expected apt, dpkg, or update process and its runtime is reasonable, wait for it to finish.
When the error does not show a PID, check the common lock files with lsof:
sudo lsof \
/var/lib/dpkg/lock-frontend \
/var/lib/dpkg/lock \
/var/cache/apt/archives/lock \
/var/lib/apt/lists/lockCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apt 2481 root 4uW REG 8,2 0 812 /var/lib/dpkg/lock-frontendThe COMMAND and PID columns identify the process. If lsof is unavailable, use fuser:
sudo fuser -v /var/lib/dpkg/lock-frontend USER PID ACCESS COMMAND
/var/lib/dpkg/lock-frontend:
root 2481 F.... aptDo not start another package command until the listed process has finished or been stopped safely.
Step 2: Check Automatic Updates
Ubuntu and Debian systems may run background package operations through systemd. Check the APT update services with:
systemctl status apt-daily.service apt-daily-upgrade.service unattended-upgrades.serviceIf any of these services is active, wait several minutes and check again:
systemctl is-active apt-daily.service apt-daily-upgrade.service unattended-upgrades.serviceinactive
inactive
inactiveOnce all three services are inactive, retry your original package command.
You can also inspect recent service messages:
sudo journalctl -u apt-daily.service -u apt-daily-upgrade.service -u unattended-upgrades.service --since "30 minutes ago"The journal shows whether the updater is downloading packages, installing them, or failing repeatedly.
Step 3: Stop a Stuck Package Process
Only stop the process when it has clearly stopped making progress. Check the terminal output or service journal first, then confirm its command, state, and elapsed time:
ps -p 2481 -o pid,stat,etime,cmdThe STAT column shows the current process state, but it does not prove that a process is stuck. A sleeping package process may still be waiting for network or disk activity, so use the command output and logs as your main evidence.
First, ask the process to terminate normally:
sudo kill 2481Wait a few seconds, then check whether it still exists:
ps -p 2481If the command prints no process row, it has exited. Avoid sending SIGKILL unless a normal termination fails, because an immediate kill gives the package manager no opportunity to clean up.
If an automatic update service owns the process, stop the service instead of killing a child process:
sudo systemctl stop apt-daily.service apt-daily-upgrade.service unattended-upgrades.serviceCheck the lock again before continuing:
sudo fuser -v /var/lib/dpkg/lock-frontendNo output means no visible process is accessing that lock file.
Step 4: Repair Interrupted Package Configuration
Stopping a package process may leave unpacked packages waiting to be configured. Complete those pending operations with:
sudo dpkg --configure -aThis command configures packages that were unpacked but not fully configured. Our dpkg command guide explains package states and other useful recovery options.
Next, repair missing or broken dependencies:
sudo apt --fix-broken installReview the proposed package changes before confirming. After the repair completes, refresh the package index:
sudo apt updateYou can then retry the original install or upgrade command.
Lock File Locations
The path in the error depends on which package-management layer is busy:
/var/lib/dpkg/lock-frontend- Frontend lock used by APT before it calls dpkg./var/lib/dpkg/lock- Lock for the dpkg package database./var/cache/apt/archives/lock- Lock for downloaded package archives./var/lib/apt/lists/lock- Lock for repository index files.
The diagnostic process is the same for each path: identify the process using the file, let it finish or stop it safely, and repair interrupted package configuration when necessary.
If No Process Holds the Lock
If lsof and fuser show no holder, do not remove the lock file. The dpkg tools keep these files in place, and the presence of a file does not mean that its lock is active.
First, confirm that no package manager is running:
ps aux | grep -E '[a]pt|[d]pkg|unattended-upgrade'Retry the original package command. If the lock error returns with a PID, another process acquired the lock between your checks. Inspect that new process before taking any other action.
Run the recovery commands only if an earlier package operation was interrupted:
sudo dpkg --configure -a
sudo apt --fix-broken installTroubleshooting
The lock is held by unattended-upgrade
Wait for the automatic update to finish and monitor it with systemctl status apt-daily-upgrade.service unattended-upgrades.service or sudo journalctl -u apt-daily-upgrade.service -u unattended-upgrades.service. Stop it only when it has clearly failed or remained stuck for an unreasonable time.
dpkg –configure -a reports dependency problems
Run sudo apt --fix-broken install to install missing dependencies and finish incomplete package operations. Then run sudo dpkg --configure -a again if the error requests it.
The lock returns immediately
Check the PID in the new error instead of assuming that the previous process restarted. An APT timer may have launched a new one-shot package operation between your checks. Inspect the services and their next scheduled runs with:
systemctl status apt-daily.service apt-daily-upgrade.service
systemctl list-timers apt-daily.timer apt-daily-upgrade.timerDo not repeatedly kill package processes. Wait for the active service to finish or stop that service only after confirming that it is stuck.
The lock error appears inside a script
Another package process may overlap with the script. For an apt-get install command, set a bounded dpkg lock timeout so the script waits instead of failing immediately:
sudo apt-get -o DPkg::Lock::Timeout=60 install -y curlThis example waits up to 60 seconds for the dpkg lock. If the timeout expires, log the failure and stop the script. Do not add rm commands for APT or dpkg lock files.
A graphical software manager is open
Close applications such as App Center, Software Updater, Synaptic, or other package frontends. Wait for their background process to exit, then retry the terminal command.
FAQ
Is it safe to delete /var/lib/dpkg/lock?
Deleting the file is not the correct first fix. The lock is associated with a running process, so removing the path does not stop that process. Identify the holder with lsof, fuser, or the PID in the error and deal with the process instead.
How long should I wait for apt-daily?
Most background checks finish within a few minutes, but upgrades can take longer depending on package downloads and installation work. Check its status and journal rather than relying on a fixed timeout.
What does dpkg –configure -a do?
It configures all packages that were unpacked but not fully configured. This is the standard recovery step after a package operation is interrupted.
Why does the error mention lock-frontend instead of lock?
APT uses a frontend lock to ensure that only one high-level package manager controls dpkg at a time. The lower-level dpkg database has its own lock as well.
Can I prevent automatic updates from taking the lock?
You can change the system’s automatic update schedule or policy, but disabling security updates only to avoid occasional lock contention is usually a poor tradeoff. It is safer to schedule maintenance commands outside the automatic update window.
Conclusion
An APT or dpkg lock error usually means package management is already active, not that the lock file is broken. Identify the holder, wait or stop it safely, then use dpkg --configure -a and apt --fix-broken install to repair any interrupted work. For more package maintenance examples, see our APT command guide
.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page