How to Force Reconfigure and Rerun Post-Installation Scripts for Debian/Ubuntu Packages Using apt-get


1 views

When working with Debian-based systems like Ubuntu, many packages (especially those with complex configurations like mailutils) execute post-installation scripts during the initial setup. These scripts typically handle:

  • Service configuration files creation
  • Database initialization
  • Interactive setup prompts
  • System user creation

The challenge arises when you either cancel this process prematurely or need to modify the initial configuration.

To properly re-run the configuration scripts for an already installed package, use this command sequence:

sudo apt-get --reinstall install mailutils
sudo dpkg-reconfigure mailutils

For a more thorough approach that also purges existing configuration:

sudo apt-get purge mailutils
sudo apt-get install mailutils

The dpkg-reconfigure command specifically targets the package's post-installation scripts (maintainer scripts). These are stored in /var/lib/dpkg/info/ with names like:

package-name.postinst
package-name.config

For mailutils specifically, you might want to check additional configuration files:

ls /etc/mail/
cat /etc/mailutils.conf

For scripting purposes or when you need to bypass interactive prompts, use debconf to pre-seed answers:

echo "mailutils mailutils/postfix_use_mailx boolean false" | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive mailutils

If configuration files were modified since installation, you might encounter:

sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall mailutils

This forces reinstallation of missing configuration files while preserving modified ones (use --force-confnew to overwrite all).


Many Debian-based packages (like mailutils) include important post-installation configuration scripts that run automatically during initial installation. When these scripts get interrupted or need to be rerun, simply reinstalling the package won't always trigger them again.

Here are three technical approaches to force package reconfiguration:

# Method 1: Purge and reinstall (most thorough)
sudo apt-get purge mailutils
sudo apt-get install mailutils

# Method 2: Use dpkg-reconfigure (specific to Debian/Ubuntu)
sudo dpkg-reconfigure mailutils

# Method 3: Manual script execution (advanced)
sudo apt-get --reinstall install mailutils
sudo /var/lib/dpkg/info/mailutils.postinst configure

Debian packages can exist in several states that affect configuration scripts:

  • installed: Package is installed with config files
  • config-files: Only configuration files remain
  • half-configured: Package is unpacked but configuration failed

For the specific mailutils case mentioned, here's the complete solution:

# First check current package status
dpkg -l mailutils

# Then either purge and reinstall (recommended)
sudo apt-get purge mailutils
sudo apt-get install mailutils

# OR use dpkg-reconfigure if package is already installed
sudo dpkg-reconfigure mailutils

If scripts still don't run properly:

# Check package configuration status
sudo dpkg --audit

# Force package into "half-configured" state
sudo dpkg --force-configure-any -r mailutils
sudo apt-get -f install

All post-installation scripts are stored in:

/var/lib/dpkg/info/[package].postinst

You can manually examine or execute these scripts if needed.