Linux dpkg-lockMedium

Ubuntu Package Lock Error: How to Unlock apt/dpkg

A package lock error in Ubuntu occurs when another process is using the package database. In this article, you'll learn how to quickly unlock the package manager and resume work.

Updated at February 17, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04 LTSUbuntu 22.04 LTSUbuntu 24.04 LTS

What the dpkg-lock error means

A package lock error in Ubuntu occurs when the system cannot access the package database because another process is already using it. The full error message usually looks like this:

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

Or:

E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

This error appears when attempting to run apt update, apt upgrade, apt install, or dpkg -i commands. It prevents installing, updating, or removing packages until the lock is released.

Common causes

The lock error occurs for the following reasons:

  1. Background automatic updates — the unattended-upgrades service may run apt in the background to install security updates.
  2. Another running apt/dpkg process — for example, you opened Software Updater or another terminal with an apt command, and they conflict.
  3. Improper termination of a previous operation — if a previous package installation was interrupted (e.g., by closing the terminal), the lock file may have been left behind.
  4. Manual script execution — user scripts or third-party programs may use dpkg directly.
  5. Malware — rare cases where malicious software locks system files.

Solution 1: Quick fix: remove the lock file

This method works if you are sure no process is using the package manager (e.g., you ran the command in two terminals by accident).

  1. Find the process holding the lock
    Run one of these commands:
    sudo lsof /var/lib/dpkg/lock-frontend
    

    Or:
    sudo fuser -v /var/lib/dpkg/lock-frontend
    

    If the command outputs nothing, check other lock files:
    sudo lsof /var/lib/dpkg/lock
    sudo lsof /var/lib/apt/lists/lock
    sudo lsof /var/cache/apt/archives/lock
    

    The output will show the PID (process ID) and process name (e.g., apt or apt-get).
  2. Terminate the found process
    Replace <PID> with the number you obtained:
    sudo kill -9 <PID>
    

    If there are multiple processes, terminate all of them. You can also use sudo killall apt or sudo pkill apt, but be careful: this will kill all apt processes.
  3. Remove the lock files
    After terminating the process, remove all possible lock files:
    sudo rm -f /var/lib/dpkg/lock-frontend
    sudo rm -f /var/lib/dpkg/lock
    sudo rm -f /var/lib/apt/lists/lock
    sudo rm -f /var/cache/apt/archives/lock
    

    The -f flag suppresses errors if the file doesn't exist.
  4. Restart the package manager
    Update the package list and try your operation again:
    sudo apt update
    sudo apt upgrade   # or sudo apt install <package>
    

Solution 2: Reboot the system

If you don't want to manually search for and kill processes, a simple system reboot will solve the problem in most cases. Reboots terminate all processes and release lock files (unless they were left due to an improper shutdown).

  1. Run:
    sudo reboot
    
  2. After the system boots, try the apt command again.
    Note: If the error returns after reboot, the lock file remained on disk (e.g., due to an interrupted operation). In this case, go back to Solution 1 and remove the file manually.

Solution 3: Recover an interrupted operation with dpkg --configure -a

If the lock occurred due to an interrupted package installation (e.g., you closed the terminal during apt upgrade), the system may be left in an "unconfigured" state. This can cause a lock.

  1. Run the recovery command:
    sudo dpkg --configure -a
    
    It will attempt to complete the configuration of all packages that were in the middle of installation.
  2. After it finishes, update the cache and try again:
    sudo apt update
    sudo apt upgrade
    
    If dpkg --configure -a doesn't help or gives a lock error, use Solution 1 to remove the lock file.

Prevention

To minimize the risk of package locks:

  • Don't run multiple terminals with apt simultaneously. Even in one terminal, avoid parallel commands (e.g., don't start a new apt upgrade before the first finishes).
  • Use apt instead of calling dpkg directly. apt automatically handles locks and dependencies.
  • Schedule automatic updates for a convenient time. Edit /etc/apt/apt.conf.d/20auto-updates or /etc/apt/apt.conf.d/10periodic so background updates don't interrupt your work.
  • Update your system regularly. Long update operations (especially with major changes) increase the chance of conflicts.
  • Check processes before critical operations. If you plan a mass installation, run ps aux | grep apt to be sure no other processes are running.
  • Avoid force-killing (kill -9) apt processes if possible. Let them finish naturally.

F.A.Q.

Why does a package lock error occur in Ubuntu?
How to safely remove the lock file?
Can automatic updates be disabled to avoid locking?
What to do if the lock doesn't release after deleting the file?

Hints

Identify the process holding the lock
Terminate the conflicting process
Remove the lock file
Restart the package manager

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