How to Fix apt Lock Error Could Not Get Lock
DodaTech
1 min read
In this tutorial, you'll learn about How to Fix apt Lock Error Could Not Get Lock. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
You run apt install or apt update and get:
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (apt-get)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
Or:
E: Could not get lock /var/lib/apt/lists/lock. It is held by process 5678 (apt)
Another apt or apt-get Process is already running, or a previous Process was interrupted and left a stale lock file.
Quick Fix
Step 1: Find the Process holding the lock
ps aux | grep -E "apt|dpkg"
Look for processes like apt-get, apt, or dpkg.
Step 2: Wait or kill the Process
If the Process is still running, wait for it to finish:
# Monitor the process
watch -n 1 "ps aux | grep -E 'apt|dpkg' | grep -v grep"
If the Process is stuck, kill it:
sudo kill -9 1234
Step 3: Remove stale lock files
If no apt Process is running, remove the stale lock files:
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/apt/lists/lock
Step 4: Reconfigure dpkg
sudo dpkg --configure -a
This fixes any interrupted package installations.
Alternative Solutions
Restart the system to clear all locks:
sudo reboot
Then try apt update again.
Prevention
- Never close a terminal while apt is running.
- Use
aptinstead ofapt-getto avoid accidental lock contention. - Run only one package manager command at a time.
- If using unattended-upgrades, wait for it to finish before manual apt commands.
← Previous
Apache APISIX Wolf-RBAC Returns 403 for Authorized Users
Next →
How to Fix Aqua Security Scanner / Image Scan Failure
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro