Fix “Unable to lock the administration directory (/var/lib/dpkg/)” in Ubuntu

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.95/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

15 Responses

  1. Jayaprakash says:

    thanks. worked well

  2. Jay-r Simpron says:

    Thank You.

  3. Misbah says:

    Thank you. Worked like a charm

  4. Hafizh says:

    Thank you so much

  5. hendrik says:

    The fix in the main post seems like a bit of overkill. Only the process actually owning the lock needs to be killed.

    You can find its PID with lsof:

    $ sudo lsof /var/lib/dpkg/lock

    Example output:

    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
    Output information may be incomplete.
    unattende 3002 root 4uW REG 8,10 0 1471282 /var/lib/dpkg/lock

    In this case, the PID is 3002, and “sudo kill 3002” or “sudo kill -9 3002” should release the lock.

    If lsof lists no process and the problem remains, the lock file may be safely deleted.

  6. Vikc says:

    Nice and easy to understand explanation.

  7. Ron HD says:

    In general, it’s always best to try a simple kill without the -9 option first. This asks the process to exit normally, which allows it to clean up first. Only if the process fails to exit, meaning it’s hung, should you kill -9, which tells to kernel to terminate it.

  8. ROMSAT says:

    Another way to remove lock file in the /var/lib/dpkg/ directory is:

    $ sudo fuser -vki /var/lib/dpkg/lock

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *