1

I accidentally deleted my /usr/bin/dpkg on my raspberry pi running debian jessie, I've literally checked out everything, nothing works, I need urgent help.

When I attempt to install any package, or even run a dpkg command I get something like:

open (2:/usr/dpkg/lock does not exist
1
  • If you’ve “literally checked out everything”, there’s not a lot anyone else can do. If you haven’t checked everything, you should edit your question to include details of what you have actually tried – and the results. You have to provide relevant details if you want others to help you. See How do I ask a good question?. Nov 20, 2015 at 14:21

3 Answers 3

3

First download the package dpkg:

apt-get download dpkg

Now you see the .deb package in your current working directory. This can be unpacked manually by:

ar x dpkg_<package_version>.deb

That package containes, amongst other things, a file called data.tar.gz. In there are the executables. Unpack it within the current directory:

tar xf data.tar.gz

Your desired executable is now in ./usr/bin/dpkg and can be copied back with:

cp ./usr/bin/dpkg /usr/bin/dpkg

Your binary is back and can therefore be called by a shell:

dpkg --version
8
  • Very good answer, except the actual format of that data.* bundle might be different. For instance, Jessie mostly (or exclusively) uses xz format which is to be unpacked using the xz package.
    – kostix
    Nov 20, 2015 at 14:25
  • returns bash: dpkg: command not found, I definitely screwed something up REALLY bad. Nov 20, 2015 at 14:30
  • @icecreamscoop At which step? Where the other steps successful? What about calling /usr/bin/dpkg?
    – chaos
    Nov 20, 2015 at 14:32
  • @kostix I did that on a debian 8 (Jesse). The data.* file was a tar gzip archive.
    – chaos
    Nov 20, 2015 at 14:33
  • 1
    @icecreamscoop Remove that directory: rm -R /usr/bin/dpkg. And then do again: cp ./usr/bin/dpkg /usr/bin/dpkg from that directory where the deb file was.
    – chaos
    Nov 20, 2015 at 14:40
1

Oh you poor unfortunate sudoer... However, this can be fixed!

First off, you need to know whether your Pi uses armel or armhf this can be found with a quick google search with the model of your Pi. Example: Raspberry pi 2 armel or armhf (Sorry, I don't know off the top of my head...)

To get the armel version of the file run:

wget http://ftp.us.debian.org/debian/pool/main/d/dpkg/dpkg_1.17.25_armel.deb

For the armhf:

wget http://ftp.us.debian.org/debian/pool/main/d/dpkg/dpkg_1.17.25_armhf.deb

Once it downloads use the command:

ar -x <package name>

This will extract a few files. The one you want is data.tar.gz extract it by using:

tar xf data.tar.gz

You now have a usr/ and sbin/ directory. One last command:

sudo cp usr/bin/dpkg /usr/bin/dpkg

Notice the positioning of the "/" in the last part of that command

Now you should again have the dpkg package back and be able to install packages to your heart's content.

Hope this Helps!

-1

Since all the solutions I tried didn't work (including the 2 which were posted here), I had to reinstall the OS on my raspberry pi using NOOBS. Thanks for all the help though.

2
  • 1
    The solution posted by @chaos works. I've tried it myself.
    – Larssend
    Nov 21, 2015 at 2:38
  • If anyone feels this doesn't work - make sure that /usr/bin/dpkg is executable: sudo chmod +x /usr/bin/dpkg
    – Lockszmith
    Jul 12, 2023 at 2:58

You must log in to answer this question.

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