34

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?

0

3 Answers 3

47

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

4
  • 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, 2014 at 16:33
  • 1
    Good answer but manually removing the lock file should be a last resort.
    – Sophit
    Jul 16, 2014 at 0:04
  • No such file or directory: /var/lib/dpkg/lock Jul 24, 2016 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.
    – dhchdhd
    Sep 12, 2017 at 21:36
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

1
  • 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. Jul 14, 2016 at 18:32
-3

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
2
  • 6
    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".
    – m3nda
    May 28, 2015 at 21:10
  • 4
    That file is empty anyway. Jul 14, 2016 at 18:27

Not the answer you're looking for? Browse other questions tagged .