dpkg only installs a package from local which apt-get installs it from local cache which is got from remote repo configure by /etc/apt/source.list, so when you run apt related commands better to run $ apt-get update first to sync local cache with remote repo.
dpkg only installs a package provided it does not solve dependency for the package, let’s say if a package depends on A, while A is not installed, install this package will fail, that’s the big difference for these two tools, so always use apt-get for published package while use dpkg for your own package.
# extract files from deb to outputdir $ dpkg-deb -x xxx.deb outputdir
# extract control files like control/preinst/postinst $ dpkg -e xx.deb
# show tar files in deb $ ar tv hello.deb rw-r--r-- 0/0 4 Mar 28 23:17 2017 debian-binary rw-r--r-- 0/0 270 Mar 28 23:17 2017 control.tar.gz rw-r--r-- 0/0 2176 Mar 28 23:17 2017 data.tar.xz
# extract a debian $ ar xv hello.deb debian-binary control.tar.gz data.tar.xz
# only extract data file and extract data.tar.xz as well $ dpkg-deb -x hello.deb
# check if deb package missed something $ lintian xx.deb
# if a file is installed by apt/dpkg, check which package it belongs $ dpkg -S /bin/cat
what happens when you install a deb package from apt/dpkg
-i, --install package-file... Install the package. If --recursive or -R option is specified, package-file must refer to a directory instead.
Installation consists of the following steps:
1. Extract the control files of the new package.
2. If another version of the same package was installed before the new installation, execute prerm script of the old package.
3. Run preinst script, if provided by the package.
4. Unpack the new files, and at the same time back up the old files, so that if something goes wrong, they can be restored.
5. If another version of the same package was installed before the new installation, execute the postrm script of the old package. Note that this script is executed after the preinst script of the new package, because new files are written at the same time old files are removed.
6. Configure the package. See --configure for detailed information about how this is done.
--unpack package-file... Unpack the package, but don not configure it. If --recursive or -R option is specified, package-file must refer to a directory instead.
--configure package...|-a|--pending Configure a package which has been unpacked but not yet configured. If -a or --pending is given instead of package, all unpacked but unconfigured packages are configured.
To reconfigure a package which has already been configured, try the dpkg-reconfigure(8) command instead.
Configuring consists of the following steps:
1. Unpack the conf files, and at the same time back up the old conf files, so that they can be restored if something goes wrong.
2. Run postinst script, if provided by the package.
The control files(post install, preinstall etc) are at /var/lib/dpkg/info
debug dpkg when install fails
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Setting up gconf2 (2.28.1-6) ... dpkg: error processing gconf2 (--configure): subprocess installed post-installation script returned error exit status 247
check why $ dpkg -i --debug=7337 xx.deb
$ dpkg --configure -D 777 gconf2 # OR run the post script with shell debug $ sh -x /var/lib/dpkg/info/gconf2.postinstpostinst configure 2.28.1-6
# if there is no script at /var/lib/dpkg/info, extract it $ dpkg -e xx.deb $ sh -x DEBIAN/postinst configure 2.28.1-6