Skip to content
FixingBook
Verifiedbeginnerest. 10 minutes

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

Match the environmentUse this guide only for Ubuntu, Debian, Pop!_OS, Mint or a clearly compatible setup.
Protect recoveryBack up important data and save encryption or account recovery keys before changing system state.
Know when to stopMake one change at a time and stop if the result differs from what the guide describes.

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 apt or apt-get open 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.

  1. Close your terminal and wait 5 to 10 minutes.
  2. Open a new terminal.
  3. Try running your apt command again.
Expert Tip

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.

  1. Open your terminal.
  2. Find the process ID (PID) holding the lock by running:
    sudo lsof /var/lib/dpkg/lock
  3. Look at the PID column in the output.
  4. 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.

  1. Remove the primary dpkg lock file:
    sudo rm /var/lib/dpkg/lock
  2. 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
  3. Reconfigure any unpacked packages:
    sudo dpkg --configure -a
  4. Fix any broken installations:
    sudo apt --fix-broken install
Critical

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

  1. Repeat the exact action that originally triggered the problem.
  2. Confirm the original error or symptom is gone and no new warning has appeared.
  3. If the guide changed a driver, service, package, or system setting, restart once and test again.
  4. 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

Consensus0%
Required100% (Weight 3)
Contributors0
Verified By YouNo
Your Weight--

Did this solution resolve your issue?

Confirming if this works strengthens verification statistics on the registry.

Sign In to VerifySign in required to verify

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.

Spotted something outdated? Suggest an edit. Maintainers review submissions within 48 hours.
Share:XReddit

Discussion (0)

No comments yet. Share your experience or verify if this fixed your issue!

Join the Discussion