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?

marked as duplicate by karel, user68186, Eric Carvalho, Mahesh, chaos Jul 22 '14 at 10:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 33 down vote accepted

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

  • 1
    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. – akp234 Jul 15 '14 at 16:33
  • 1
    Good answer but manually removing the lock file should be a last resort. – Sophit Jul 16 '14 at 0:04
  • No such file or directory: /var/lib/dpkg/lock – Igor G. Jul 24 '16 at 20:54
  • 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. – Barry Sep 12 '17 at 21:36

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

  • 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. – Alexis Wilke Jul 14 '16 at 18:32

The /var/lib/dpkg/lock is actually a file. If you think it is important, just rename it don't want to remove it.

sudo mv /var/lib/dpkg/lock /var/lib/dpkg/lock-backup
  • 5
    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". – erm3nda May 28 '15 at 21:10
  • 3
    That file is empty anyway. – Alexis Wilke Jul 14 '16 at 18:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.