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, or dpkg commands 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

  1. 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.
  2. 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.
  3. 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 PID with the actual process number.
    • Be careful not to kill a process that is still actively installing updates unless you are sure it is frozen.
  4. 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.
  5. 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.
  6. 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.
  7. 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.

Download Kudu Free →

Fix this automatically with Kudu

Run a free system scan to detect and resolve this issue automatically — no manual steps required.

Download Kudu Free →