I ended up dealing with a software meant to be deployed using dpkg. The .deb package works fine on the test env but fail on staging. Both are running the same version of Ubuntu but I am not 100% sure of the rest of the configs. How to debug this dpkg issue further?

The installation fails like this:

sudo dpkg -i --debug=7337 package.deb 
D000010: ensure_pathname_nonexisting `/var/lib/dpkg/tmp.ci'
(Reading database ... 201812 files and directories currently installed.)
Unpacking myProprietarySoftware (from package.deb) ...
D000001: process_archive oldversionstatus=not installed
D000002: fork/exec /var/lib/dpkg/tmp.ci/preinst ( install )
dpkg: error processing package.deb (--install):
 subprocess new pre-installation script returned error exit status 1
D000002: maintainer_script_new nonexistent postrm `/var/lib/dpkg/tmp.ci/postrm'
D000010: ensure_pathname_nonexisting `/var/lib/dpkg/tmp.ci'
D000010: ensure_pathname_nonexisting running rm -rf
D000010: ensure_pathname_nonexisting `/var/lib/dpkg/reassemble.deb'
Errors were encountered while processing:
  • This question is also useful if you're encountering this error while using apt-get because apt-get is calling dpkg underneath. Look in the output for the .deb package involved which is probably gonna be under /var/cache/apt/archives.
    – e18r
    Commented Mar 16, 2017 at 15:10

4 Answers 4


The package's .preinst script is failing for some reason.

To find out why, examine the script in /var/lib/dpkg/info/PACKAGENAME.preinst

If you want to see exactly which line the script is failing on, edit the .preinst script and add set -x immediately after the #! line. This turns on execution tracing in the script.

NOTE: This assumes that the .preinst script is a shell script (either posix sh or bash). Almost all .preinst (and .postinst, .prerm, and .postrm) scripts are shell scripts but they don't have to be, they could be any executable. e.g. on my main desktop machine with 9104 packages installed, 14 are perl scripts, 1 is a compiled executable (bash's preinst - it can't assume there is a functioning shell already installed), and all of the rest are shell scripts...9041 are POSIX shell scripts, 63 are bash scripts. If the .preinst is perl or python or something else, you'll have to figure out how to enable debugging or execution trace mode or similar in that language.

Then run dpkg --configure --pending.

This will cause dpkg to try to configure the half-installed package. DO NOT reinstall it with dpkg -i, that will overwrite your edited .preinst script with the version in the .deb package.

This may give you enough information to fix the problem. It may be something simple like an unexpected or uncaught exit code from a program (most .preinst etc scripts have set -e, to make them terminate on the first error), or assuming that a directory already exists (and this may be due to an undeclared dependency in the package's debian/control file - i.e it should depend on foo but doesn't. just install foo anyway)

Once it's fixed, run dpkg --configure --pending again, and the package should be properly installed.

If the .preinst script is buggy, there's a reasonable chance that the .postinst (and/or .prerm and .postrm) scripts will be too. You may need to fix them as well.

Don't forget to submit a bug report to whoever made the package so they can fix it.


Your packaged software includes a "pre-installation script" (preinst) which is failing. This is a shell-script embedded within the .deb file. You can extract it with:

 dpkg-deb -e some-deb.deb out-dir

Then you can look at out-dir/preinst and see if you can figure out why it is failing.

If you want to modify that script and rebuild the .deb (perhaps to add some debugging code), try

 dpkg-deb -x some-deb.deb another-out-dir
 dpkg-deb -e some-deb.deb another-out-dir/DEBIAN
 (modify another-out-dir/DEBIAN/preinst)
 dpkg-deb -b another-out-dir some-deb2.deb

You will need to extract the file and see why the preinst script exits with code 1.

Not sure if there was a discussion on UNIX.SE related to how to do this but you can take a look at this question from AskUbuntu to get an idea on how to extract.

After this you will have to manually run the preinst script to see why the package installation fails.


If you want to edit the package directly try this:


if [[ -z "$1" ]]; then
  echo "Syntax: $0 debfile"
  exit 1

TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
OUTPUT=`basename "$DEBFILE" .deb`.modfied.deb

if [[ -e "$OUTPUT" ]]; then
  echo "$OUTPUT exists."
  rm -r "$TMPDIR"
  exit 1

dpkg-deb -x "$DEBFILE" "$TMPDIR"
dpkg-deb --control "$DEBFILE" "$TMPDIR"/DEBIAN

if [[ ! -e "$TMPDIR"/DEBIAN/control ]]; then
  echo DEBIAN/control not found.

  rm -r "$TMPDIR"
  exit 1


MOD=`stat -c "%y" "$CONTROL"`

if [[ "$MOD" == `stat -c "%y" "$CONTROL"` ]]; then
  echo Not modfied.
  echo Building new deb...
  dpkg -b "$TMPDIR" "$OUTPUT"

rm -r "$TMPDIR"

Source: http://ubuntuforums.org/showthread.php?t=636724

  • Looks like this script was writen to modify the control file (and rebuild the package), not the preinst script per the OP's problem.
    – arielf
    Commented May 26, 2016 at 18:02

You must log in to answer this question.

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