APT fails when executing post-invoke scripts after package updates, often due to corrupted cache files or problematic metadata packages. Fix by clearing cache, reinstalling libappstream4, or checking script permissions.
The APT::Update::Post-Invoke error occurs when APT attempts to run cleanup or maintenance scripts after updating the package index. This hook mechanism, configured in /etc/apt/apt.conf.d/, typically runs tasks like refreshing application metadata caches or removing old package files. When these scripts encounter errors—such as corrupted cache files, broken symbolic links, or problematic dependencies—APT halts the update process and reports this error. This error is particularly common with the appstreamcli utility, which manages software component metadata. If libappstream4 is corrupted or if cache files become malformed, the post-invoke script fails and blocks further package operations.
Remove corrupted cache files and rebuild from scratch:
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get clean
sudo apt-get updateThis clears all package metadata and rebuilds it fresh. Often this alone resolves the issue without further steps.
The libappstream4 library is frequently the culprit. Reinstall it to restore correct metadata handling:
sudo apt-get install --reinstall libappstream4If this step alone fails, combine it with the cache clear above. libappstream4 is used to manage software component metadata, and corruption here directly breaks the post-invoke script.
If the error persists, check for corrupted XML metadata files:
ls -la /var/cache/app-info/xmls/If fwupd.xml or other files appear corrupted, you can attempt to fix them manually or remove and rebuild:
sudo rm /var/cache/app-info/xmls/fwupd.xml
sudo appstreamcli refresh-cacheNote: fwupd.xml is regenerated automatically when firmware update tools run, so removing it is safe.
Broken symbolic links can confuse post-invoke scripts. Check for common issues:
ls -la /usr/bin/python*
lsof | grep pythonIf you see broken or unexpected links, correct them:
sudo ln -sf /usr/bin/python3 /usr/bin/pythonRun apt-get update again to verify the fix.
Check for custom scripts you may have configured:
ls -la /etc/apt/apt.conf.d/
grep -r "Post-Invoke" /etc/apt/apt.conf.d/If you find a custom script, verify it is executable and has no syntax errors:
# Test the script directly
bash -n /path/to/script.sh # Check for syntax errors
sudo bash -x /path/to/script.sh # Run with debug outputIf the script is unnecessary, temporarily disable it:
sudo mv /etc/apt/apt.conf.d/50unattended-upgrades /etc/apt/apt.conf.d/50unattended-upgrades.disabledThen retry apt-get update.
Docker versions 20.10.5 through 20.10.7 contain a bug in how they execute post-invoke hooks. If building Docker images, upgrade Docker to 20.10.11 or later:
docker --version # Check current versionConsult Docker release notes for your platform to upgrade to the latest stable version. This resolves the APT issue entirely for Docker-based builds.
APT hooks are configured in /etc/apt/apt.conf and /etc/apt/apt.conf.d/. The syntax for post-invoke hooks is:
APT::Update::Post-Invoke { "/path/to/script"; };Multiple hooks are executed in order using /bin/sh. If any fail, APT aborts. The most common post-invoke scripts include:
- appstreamcli refresh-cache (updates application metadata)
- apt-listchanges (shows package changes)
- unattended-upgrades hooks (for automatic updates)
For debugging, run apt-get with verbose output:
sudo apt-get -o Debug::pkgAcquire::Worker=1 updateThis shows which exact post-invoke script is failing and its error output. In CI/CD environments, consider disabling post-invoke scripts entirely if not needed:
sudo apt-get -o Dir::Etc::SourceParts="" updateAlternatively, suppress errors in unattended upgrade scenarios:
sudo unattended-upgrade -d # Dry run to testE: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT