How do I unlock /var/lib/dpkg/lock?
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
Related videos on Youtube

akp234
Updated on September 18, 2022Comments
-
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 itsudo kill -TERM PID
but it immediately tries to finish the installation again and gets stuck.How do I resolve this?
-
akp234 over 8 yearsI 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 over 8 yearsGood answer but manually removing the lock file should be a last resort.
-
m3nda over 7 yearsThis 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 over 6 yearsThat file is empty anyway.
-
Alexis Wilke over 6 yearsWith 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 over 6 yearsNo such file or directory: /var/lib/dpkg/lock
-
dhchdhd over 5 yearsUse
pgrep -f 'dpkg|apt'
instead ofps ... | grep ...
because it's wrong;ps ... | grep -v grep | grep ...
is the old way to do it.