Lost/Deleted dpkg (package manager for Debian). How do I get it back?
Solution 1:
Depending exactly what you removed, you may be able to rescue the situation by extracting the necessary parts from a manually downloaded .deb
file. The trick, of course, is finding a way to unpack the .deb
file without a working dpkg
- fortunately there's a solution here
How to extract and install .deb without the command dpkg?
First go to packages.ubuntu.com and download the appropriate .deb
file for your OS version and architecture e.g.
mkdir debroot && cd debroot
wget http://mirrors.kernel.org/ubuntu/pool/main/d/dpkg/dpkg_1.18.4ubuntu1_amd64.deb
Now unpack the deb file using ar
in place of the usual dpkg -x
ar -x dpkg_1.18.4ubuntu1_amd64.deb
(replace dpkg_1.18.4ubuntu1_amd64.deb
with name of the actual deb that you downloaded). You should now have the following contents
control.tar.gz data.tar.gz debian-binary dpkg_1.18.4ubuntu1_amd64.deb
The package's files should be located in the data.tar.gz
so to extract the dpkg
binary file locally
tar xf data.tar.gz ./usr/bin/dpkg
If that worked, you should have a file at ./usr/bin/dpkg
which you can copy to your /usr/bin
directory
sudo cp ./usr/bin/dpkg /usr/bin/
[Note that you could untar the file directly relative to /
using sudo tar -C ...
but doing it in two steps just feels a little safer.]
If that works, I'd recommend re-installing the whole thing from the repository for consistency i.e.
sudo apt-get update
sudo apt-get install --reinstall dpkg
(on newer systems, you can replace apt-get
by apt
).
Solution 2:
Download the dpkg package for your release from https://launchpad.net/ubuntu/+source/dpkg/.
Extract the file.
cd
to the root of the dpkg source directory.
./configure
make
sudo make install
You may need to download some packages if ./configure
fails