Linux apt-lock-failedMedium

apt-lock-failed Error: Causes and 5 Solutions

This article explains what the apt-lock-failed error means, when it occurs, and provides 5 practical ways to fix it—from simple waiting to forcefully terminating processes. You'll learn how to safely unlock the APT package manager.

Updated at February 16, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Debian 11/12Ubuntu 20.04/22.04/24.04Linux Mint 21/22any APT-based distro

What the apt-lock-failed Error Means

The error E: Could not get lock /var/lib/dpkg/lock or E: Unable to acquire the dpkg frontend lock means that the APT package manager (and its low-level component, dpkg) cannot access its critical files because they are already locked by another process.

This is a system safeguard against simultaneous modification of the package database, which could damage it. The error appears when attempting to run any command that changes the system state: apt install, apt update, apt upgrade, apt remove, dpkg -i, etc.

A typical full message:

E: Could not get lock /var/lib/dpkg/lock. It is held by process 1234 (apt)
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (apt)

Common Causes

  1. An active APT/dpkg process in another terminal. You started an installation/update in one terminal window and are trying to run another apt command in parallel.
  2. A background automatic process. Services like unattended-upgrades (automatic updates) or apt-daily.service may be running in the background.
  3. A "hung" or abnormally terminated process. A previous apt/dpkg session was interrupted (e.g., via Ctrl+C or a system crash), but the lock file remained.
  4. Insufficient privileges. Attempting to run an apt command without sudo can sometimes lead to strange access errors, though the error message is usually different.
  5. Filesystem issues. Rarely—inode corruption or a tmpfs mount with insufficient space.

Most often, the lock is temporary. A background update process (especially on Ubuntu/Debian) may run for 5-15 minutes.

What to do:

  1. Wait 2-3 minutes.
  2. Try the command again.
  3. If that doesn't help, check what is actually running (see Solution 2).

💡 Tip: You can add a wait timeout to the command so APT itself waits for the lock to be released:
sudo apt-get -o DPkg::Lock::Timeout=60 update (waits 60 seconds).

Solution 2: Find and Kill the Process Holding the Lock

This is the primary and safest method if you are certain the background process isn't performing a critical operation.

Steps:

  1. Find the PID (process ID) holding the lock:
    sudo lsof /var/lib/dpkg/lock
    

    Or more comprehensively (will also show lock-frontend):
    sudo lsof /var/lib/dpkg/lock-frontend
    

    Example output:
    COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    apt     1234 root    3uW  REG    8,2        0 12345 /var/lib/dpkg/lock-frontend
    

    Here, PID = 1234.
  2. Assess the process. If the COMMAND column shows apt, apt-get, aptitude, dpkg, or unattended-upgr, it is indeed an APT process.
  3. Safely terminate the process:
    sudo kill -9 1234
    

    Use -9 (SIGKILL) only if a regular kill 1234 (SIGTERM) fails.
  4. Verify the process has stopped:
    ps aux | grep -E "(apt|dpkg)" | grep -v grep
    

    The output should be empty.
  5. Remove the lock files (see Solution 3).

Solution 3: Forcefully Remove Lock Files (Only After Stopping Processes!)

IMPORTANT: Perform this step only after you have confirmed (via Solution 2) that no APT process is running. Removing a lock file while a process is active will cause serious package database corruption, requiring recovery.

Command to remove all standard APT lock files:

sudo rm -f /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lock

The -f flag ignores non-existent files.

Solution 4: Recover dpkg State After a Crash

If the error occurred after forcibly terminating (e.g., Ctrl+C) a package installation, the dpkg database may be in a "half-configured" state.

Run:

sudo dpkg --configure -a

This command will finish configuring any packages whose installation was interrupted. After it completes successfully, normal apt commands should work.

Solution 5: Reboot the System (Last Resort)

If the previous methods fail and you cannot identify the process (e.g., in a Docker container or minimal system), the simplest solution is to reboot the machine.

sudo reboot

After reboot, all processes will be terminated and lock files cleared by the kernel. Use this method if you are unsure of your actions.

Preventing the apt-lock-failed Error

  1. Avoid parallel installations. Do not run apt install in multiple terminals simultaneously.
  2. Use a lock timeout. Add -o DPkg::Lock::Timeout=60 to commands so APT waits instead of failing.
    sudo apt-get -o DPkg::Lock::Timeout=60 update
    
  3. Disable automatic updates (if they interfere) if you manage a server manually. For Ubuntu/Debian:
    sudo systemctl stop unattended-upgrades
    sudo systemctl disable unattended-upgrades
    
  4. Regularly check system logs for dpkg/apt errors: sudo journalctl -u apt-daily.service -b.
  5. Do not interrupt (Ctrl+C) apt and dpkg processes unless absolutely necessary. It's better to let them finish.

F.A.Q.

What is a lock file in APT and why is it needed?
Can I just delete the lock file? Is it safe?
How to prevent the error from occurring in the future?

Hints

Identify which process holds the lock
Terminate the problematic process (if safe)
Remove the lock file (if the process has terminated)
Restart dpkg configuration (if needed)
Retry the original apt command

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community