Yesterday I had some problem with /var/lib/dpkg/lock
during update. I knew that in such cases removing lock file could solve problem. So I tried to do it, but by mistake I removed all DPKG directory. So now I cannot do any update, install, upgrade and so on.
I try via Software Center, Terminal, Qapt, Synaptic. None of these work because all of them do such operations via dpkg
. And as my dpkg is corrupted, so I have problem.
How can I completely restore DPKG? I have downloaded dpkg_1.16.1.2ubuntu7_amd64.deb
(I use 64bit Ubuntu 12.04) file, but what to do with it in terminal? Simple double-clicking on .deb
opens Software Center and you already know, it doesn't work.
P.S. Terminal gives such error:
dpkg: error: cannot read info directory: No such file or directory
E: Sub-process /usr/bin/dpkg returned an error code (2)
Best Answer
Okay I haven't tried this, but it should work I think.
First boot from a live CD.
Next open a terminal and type
From this you want to determine the partition that your Ubuntu installation is on. If you have only one hard drive it will be
/dev/sdaX
, whereX
is the partition number.Next mount the Ubuntu installation's partition replacing
X
with the correct partition number.Next navigate to the directory where
dpkg_1.16.1.2ubuntu7_amd64.deb
is and use this command:Hopefully this will work, and you can reboot into your Ubuntu installation and find that
dpkg
has been reinstalled. If there are any errors let me know and I will try to help you.edit:
I've been reading through the
dpkg
manpage and I think the command I suggested above might not work. Here are the relevant sections of the manpage for reference.using
--root=dir
as I suggested would set the admin folder to/mnt/var/lib/dpkg
--the folder that you deleted.Instead try this:
This will use the liveCD's
/var/lib/dpkg
folder, but the--force-overwrite
flag should make it install even though it thinks the package is already installed.Good luck!
edit2
While this should work to reinstall
dpkg
I don't think it will rebuild the package lists that are in/var/lib/dpkg
. Following the advice in izx's comment to copy the directories/file from a liveCD and go from their is probably your best bet.