Fix Could not get lock /var/lib/dpkg/lock Error in Ubuntu
Resolves the common apt package manager error where dpkg is locked by another process.
Confirmed working on: Ubuntu · Debian · Pop!_OS · Mint
Before you begin
Problem overview
The package manager fails to run and displays a “could not get lock” error. This prevents you from installing, updating, or removing software on your system.
Common causes
- A background update service is currently running.
- Another terminal window has
aptorapt-getopen and running. - A previous software installation crashed and left a stale lock file behind.
Solution 1: Wait for background updates
Automatic updates often run in the background shortly after you boot up the system.
- Close your terminal and wait 5 to 10 minutes.
- Open a new terminal.
- Try running your
aptcommand again.
If you have a slow internet connection, background updates might take longer than 10 minutes to finish.
Solution 2: Find and kill the locking process
If you suspect a stalled process is holding the lock, you can find it and stop it manually.
- Open your terminal.
- Find the process ID (PID) holding the lock by running:
sudo lsof /var/lib/dpkg/lock - Look at the PID column in the output.
- Kill the process using its PID:
sudo kill -9 <PID>
Solution 3: Remove the lock files manually
When no processes are running but the error persists, you have a stale lock file.
- Remove the primary dpkg lock file:
sudo rm /var/lib/dpkg/lock - Remove additional frontend and archive locks:
sudo rm /var/lib/apt/lists/lock sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock-frontend - Reconfigure any unpacked packages:
sudo dpkg --configure -a - Fix any broken installations:
sudo apt --fix-broken install
Removing lock files while a package installation is actively running can corrupt your system. Only do this if you confirm no apt processes are active.
Confirm the result
- Repeat the exact action that originally triggered the problem.
- Confirm the original error or symptom is gone and no new warning has appeared.
- If the guide changed a driver, service, package, or system setting, restart once and test again.
- If the result is worse or unexpected, stop. Reverse only the last change using its documented restore option; if none is documented, use your backup or qualified support.
Questions about this fix
Can I just restart my computer to fix this?
Restarting often resolves the lock, but it might interrupt a critical update. It is better to check what is running first.
Is it safe to delete the lock file?
Deleting the lock file is a last resort. Do it only if you are certain no package installation is actively running.
Did this fix work for you?
Weighted Consensus Protocol
Did this solution resolve your issue?
Confirming if this works strengthens verification statistics on the registry.
FixingTeam10,000 rep
Official Project Maintainers
The core engineering and moderation team behind FixingBook. We curate, verify, and maintain the standards of the troubleshooting ledger.
Discussion (0)
No comments yet. Share your experience or verify if this fixed your issue!
