How to Fix Could Not Get Lock Error on Linux
Resolve APT lock errors on Linux and clean package-related clutter with help from Kudu.
By Kudu Team
Fix this automatically with Kudu
Run a free system scan to detect and resolve this issue automatically — no manual steps required.
Download Kudu Free →What Causes This?
The “Could not get lock” error on Linux usually happens when APT or DPKG is already being used by another process. This often means a package update is running in the background, Software Updater is open, or a previous install was interrupted and left a lock file behind. In some cases, the package database is also left in an unfinished state and needs to be repaired before updates will work again.
Common Symptoms
- You see messages like
Could not get lock /var/lib/dpkg/lock-frontend apt,apt-get, ordpkgcommands fail immediately- Software Updater or package installs get stuck or refuse to start
- You recently stopped an update, rebooted during an install, or closed the terminal mid-process
- New apps or system updates will not install
How to Fix It Manually
-
Wait a few minutes and try again
- Sometimes another update process is still finishing in the background.
- If you just booted the system, give it 2-5 minutes, then rerun your command.
-
Check whether APT or DPKG is already running
- Open a terminal.
- Run:
ps aux | grep -E 'apt|dpkg|unattended' - Look for active processes such as
apt,apt-get,dpkg,unattended-upgrade, or a package manager GUI. - If you see Software Updater or another package tool open, close it first.
-
Stop the stuck package process if it is clearly hung
- If a process has been stuck for a long time and is not doing any work, note its PID from the previous command.
- End it with:
sudo kill -9 PID - Replace
PIDwith the actual process number. - Be careful not to kill a process that is still actively installing updates unless you are sure it is frozen.
-
Remove leftover lock files
- After confirming no package process is running, delete the lock files:
sudo rm -f /var/lib/dpkg/lock-frontend sudo rm -f /var/lib/dpkg/lock sudo rm -f /var/cache/apt/archives/lock sudo rm -f /var/lib/apt/lists/lock - These files can remain after a crash or interrupted update.
- After confirming no package process is running, delete the lock files:
-
Repair the package database
- Run:
sudo dpkg --configure -a - Then fix broken dependencies if needed:
sudo apt --fix-broken install - This finishes incomplete package setup and repairs common package issues.
- Run:
-
Update package lists and test installation again
- Refresh APT:
sudo apt update - Then try your original install or upgrade command again.
- If the error is gone, the lock issue has been resolved.
- Refresh APT:
-
Restart the system if the problem keeps coming back
- A reboot can clear stuck background update services.
- After restarting, open a terminal and run:
sudo dpkg --configure -a sudo apt update
Fix It Automatically with Kudu
If you use Linux alongside Windows, Kudu can help by cleaning package-related clutter, leftover installer files, and other system junk that builds up over time. It gives you a faster way to spot maintenance issues and keep your PC clean without digging through files manually.
Fix this automatically with Kudu
Run a free system scan to detect and resolve this issue automatically — no manual steps required.
Download Kudu Free →Related guides
How to Remove App Cache on Linux
Clean application cache on Linux to recover space and reduce clutter using Kudu.
How to Fix Apps Opening Slowly on Linux
If Linux apps take too long to open, Kudu can help clean caches and reduce system clutter.
How to Remove APT Cache on Linux
Free up storage by cleaning APT cache files on Linux with Kudu’s cleanup tools.
How to Fix a Full /boot Partition on Linux
If your Linux /boot partition is full, Kudu can help clean related leftovers and recover space.