A dpkg post-installation script failed during package installation. This happens when a package's configuration script encounters an error after the main package files are extracted. Common causes include corrupted installations, broken dependencies, disk space issues, or DKMS module compilation failures.
This error occurs when dpkg (Debian package manager) runs the post-installation script for a package and that script exits with status code 1, indicating failure. Post-installation scripts handle final configuration tasks like updating system files, registering services, or compiling kernel modules. When the script fails, the package remains partially configured and subsequent operations may fail. The error message indicates the script encountered an unrecoverable problem. This could be a missing dependency, insufficient disk space, permission issues, or a problem specific to your system configuration.
Run this command to fix any packages that are installed but not fully configured:
sudo dpkg --configure -aThis tells dpkg to configure all packages that have pending configuration. In many cases, this resolves the issue automatically.
If the above doesn't work, repair any broken dependencies:
sudo apt install -fThe -f flag stands for --fix-broken and will attempt to install missing packages or upgrade packages to fix dependency issues.
Verify you have sufficient disk space, especially in the /boot and / partitions:
df -hIf any partition shows 100% or close to it (especially /boot), you'll need to free up space before the package can complete installation. Remove old kernel images or unnecessary files.
Look at the full error message to identify which specific package is causing the issue. The error will typically show the package name. You can check the dpkg log for more details:
cat /var/log/dpkg.log | tail -20This shows recent dpkg operations and may reveal what failed.
Once you've identified the package, try removing and reinstalling it:
sudo apt remove <package-name>
sudo apt install <package-name>Replace <package-name> with the actual package name. This forces a clean installation from scratch.
If the error mentions DKMS, kernel modules, or drivers (like nvidia, displaylink, evdi), try rebuilding the DKMS modules:
sudo dkms autoinstallYou can check which DKMS modules are installed:
dkms statusIf a specific module is failing, you can check its build log:
cat /var/lib/dkms/<module-name>/<version>/build/make.logClean the apt cache and refresh package lists:
sudo apt clean
sudo apt updateThen try installing packages again. This clears any corrupted cache that might be interfering.
If all else fails, you can temporarily bypass the problematic post-installation script. This is a last resort:
ls /var/lib/dpkg/info/ | grep <package-name>Locate the .postinst file for your package, then move it:
sudo mv /var/lib/dpkg/info/<package-name>.postinst /tmp/<package-name>.postinst.bakNow try reconfiguring:
sudo dpkg --configure -aWARNING: This bypasses important configuration steps. Only use if the package is non-critical and you understand the consequences.
Post-installation scripts are critical for completing package setup. They often handle tasks like:
- Registering systemd services or init.d scripts
- Updating the GRUB bootloader configuration
- Compiling DKMS kernel modules
- Setting up user accounts or permissions
- Updating the initramfs (initial RAM filesystem)
Different packages have different requirements. For example, linux-image packages may fail if there's no /boot/grub directory. DKMS-based packages (like NVIDIA drivers) fail if compilation fails due to missing kernel headers or build tools.
Always check the error message carefully for clues about which specific step failed. The error number (1, 127, etc.) and any preceding error messages are crucial for diagnosis. If you need to manually debug a post-installation script, you can examine it at /var/lib/dpkg/info/<package-name>.postinst - it's a shell script and may give clues about what it's trying to do.
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt