0

I have host without dpkg so I need to install it.
I followed the instructions from here and here.

On both of these answers they wrote that I need to download the file:

wget http://security.ubuntu.com/ubuntu/pool/main/d/dpkg/dpkg_1.17.5ubuntu5.2_i386.deb
or
wget http://security.ubuntu.com/ubuntu/pool/main/d/dpkg/dpkg_1.17.5ubuntu5.2_amd64.deb

and use tar like that:

tar x dpkg*.deb data.tar.gz
tar xfvz data.tar.gz ./usr/bin/dpkg
cp ./usr/bin/dpkg /usr/bin/

But after running tar x dpkg*.deb data.tar.gz it failed:

[root@webtl1 ~]# tar x dpkg*.deb data.tar
tar: Refusing to read archive contents from terminal (missing -f option?)
tar: Error is not recoverable: exiting now

I followed this link:
https://askubuntu.com/questions/143107/how-to-extract-archives-to-file-system-in-terminal
And tried to use tar xvzf dpkg*.deb data.tar.gz but it also failed:

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

Any idea how I can tar the deb file to data.tar.gz ?

EDIT:
If you want to reproduce go to:
https://www.katacoda.com/courses/prometheus/getting-started

run:
wget http://security.ubuntu.com/ubuntu/pool/main/d/dpkg/dpkg_1.17.5ubuntu5.2_amd64.deb
and then try tar x dpkg*.deb data.tar.gz.

E235
  • 383

2 Answers2

5

Debian packages are ar archives with tarballs inside, not tar-in-tar. The command needs to be

ar x dpkg*.deb data.tar.gz

rather than tar x. The first answer you linked and quoted from has incompetently plagiarised from the second and given you broken instructions (whether through hypercorrection or trying to cover its tracks I don't know).

It's possible you'd need a different name to data.tar.gz for a different compression (it's changed over time), but just

ar x dpkg*.deb

then tar xaf data.tar.* ./usr/bin/dpkg should sort you out regardless of what compression was used. It will extract some extra files (control.tar.*, debian-binary, perhaps some others) that you can ignore or delete.

The rest of the instructions should be fine.

Michael Homer
  • 76,565
3

I have host without dpkg so I need to install it.

No, you don't.

Even if you managed to obtain a version of the dpkg program, it wouldn't be usable. Dpkg needs some other programs and data files. Manually assembling everything that is required to run dpkg would be challenging even for someone who is familiar with Unix command line tools.

Dpkg is the low-level package management tool for Debian and derived distributions. If you have a host without dpkg, it means it's running a different distribution which uses different package management tools. For example, CentOS (the most popular choice of non-Debian-based distribution for hosting) uses Yum. (Yum is the equivalent of apt, which is the tool you would normally use on a Debian-based distribution; the low-level packaging tool corresponding to dpkg is rpm.) Your host's documentation should clearly indicate what distribution it is running, but if you can't find this information, see this thread for how to find out empirically.

If you already know how to use dpkg and apt, the Pacman Rosetta is a handy translation table for common tasks.

If you really want to install Debian or Ubuntu packages on a different Linux distribution, use Debootstrap to set up a chroot environment. The chroot environment will behave mostly independently of the already-installed system: it will have its own set of programs, but the same network configuration, and you can give it access to the hosts's data.