| Issue | E: Unable to lock directory /var/lib/apt/lists/ |
|---|---|
| Common Cause | Another package manager (like Synaptic or a background update) is running, or a previous process crashed. |
| Quick Fix | Identify the PID using lsof, kill the process, and manually remove the lock files. |

What is the “E: Unable to lock directory” Error?
The “E: Unable to lock directory” error in Kali Linux occurs when the APT (Advanced Package Tool) system attempts to access the package database while it is already in use. Linux uses lock files to prevent multiple processes from modifying the database simultaneously, which could lead to system corruption.
This error typically appears during a sudo apt update or sudo apt upgrade command. It indicates that either a background update is currently running, or a previous installation process was interrupted improperly, leaving “stale” lock files behind.
Step-by-Step Solutions
Step 1: Check for Background Processes
Before deleting files, check if another instance of APT is running. Use the following command to find the Process ID (PID) of the locking application:
sudo lsof /var/lib/dpkg/lock-frontend
If a PID is returned, wait for that process to finish or terminate it safely.
Step 2: Kill the Conflicting Process
If the process is frozen, you can force it to stop. Replace <PID> with the number found in the previous step:
sudo kill -9 <PID>
Step 3: Remove the Lock Files Manually
If no processes are running but the error persists, you must delete the lock files manually. Execute these commands in order:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
Step 4: Reconfigure the Package Manager
After removing the locks, you must fix any interrupted configurations to ensure the database is consistent:
sudo dpkg --configure -a
Step 5: Run the Update Again
Finally, refresh your package lists and upgrade your system to verify the fix works:
sudo apt update && sudo apt upgrade -y