How do I unlock /var/lib/dpkg/lock?

133,268

Solution 1

sudo rm /var/lib/dpkg/lock should do the trick. You can use ps afx|grep dpkg to check if there is still a process runnning at the same time. sudo killall dpkg will stop all running dpkg processes.

If you need to cancel the dropbox installation, try sudo dpkg --force-remove-reinstreq --remove nautilus-dropbox

Solution 2

It means that software center or another terminal is still running a package operation, force removing it is not really recommended as it can cause corruption, but try closing those and if that doesn't do the trick then reboot and just open a terminal window and nothing else to install/do a package operation

Share:
133,268

Related videos on Youtube

akp234
Author by

akp234

Updated on September 18, 2022

Comments

  • akp234
    akp234 3 months

    I attempted to install dropbox on my Ubuntu system, but now I am unable to install or uninstall any software. I get this error:

    E: Unable to lock the administration directory /var/lib/dpkg/lock?
    

    I have already tried killing dpkg and restarting it sudo kill -TERM PID but it immediately tries to finish the installation again and gets stuck.

    How do I resolve this?

  • akp234
    akp234 over 8 years
    I did not use the first command, as I've heard this can cause a serious problems if the program is still running. The sudo dpkg --force-remove-reinstreq --remove nautilus-dropbox did the trick though.
  • Sophit
    Sophit over 8 years
    Good answer but manually removing the lock file should be a last resort.
  • m3nda
    m3nda over 7 years
    This makes no sense, even if backup everything will not harm you. If you remove a lock manually is assumed to break the process flow that creates the lock, so there's no reason to backup it. Run again the process then the lock will be created "on-demand".
  • Alexis Wilke
    Alexis Wilke over 6 years
    That file is empty anyway.
  • Alexis Wilke
    Alexis Wilke over 6 years
    With auto-update, it is often that apt-get automatically starts on a reboot. The OP has a problem with installation failing, so I do not think that this would help much.
  • IgorGanapolsky
    IgorGanapolsky over 6 years
    No such file or directory: /var/lib/dpkg/lock
  • dhchdhd
    dhchdhd over 5 years
    Use pgrep -f 'dpkg|apt' instead of ps ... | grep ... because it's wrong; ps ... | grep -v grep | grep ... is the old way to do it.