While refreshing software repositories in Ubuntu using sudo apt update or launching the Ubuntu Software centre, users often encounter terminal warnings such as: “E: Problem executing scripts APT::Update::Post-Invoke-Success ‘if /usr/bin/test -w /var/cache/appstream; then /usr/bin/appstreamcli refresh-cache > /dev/null; fi'” or simply “appstreamcli refresh failed.”
AppStream is the metadata framework that supplies descriptive software information, screenshots, and icons to graphical software stores in Ubuntu. When an incomplete update or corrupted repository mirror generates invalid XML/YAML metadata blobs, appstreamcli crashes while parsing the catalogue cache. Follow these proven terminal commands to purge corrupted caches and rebuild the AppStream database.
Manually Purge Corrupted AppStream Cache Directories
The fastest way to eliminate the error is to wipe out the corrupted AppStream cache database entirely, allowing Ubuntu to rebuild clean metadata structures from scratch.
- Open the Terminal application (Ctrl + Alt + T).
- Remove all cached AppStream metadata files:
sudo rm -rf /var/cache/appstream/* - Also remove temporary APT package lists that may contain malformed AppStream archive fragments:
sudo rm -rf /var/lib/apt/lists/*appstream* - Recreate the clean cache directory structure:
sudo mkdir -p /var/cache/appstream - Test running the manual refresh command to verify clean generation:
sudo appstreamcli refresh-cache --force
Identify and Remove Malformed Third-Party PPA Repositories
Outdated or abandoned Personal Package Archives (PPAs) frequently publish legacy AppStream metadata that violates modern AppStream XML specification standards, causing the parser to fail.
- Run
sudo apt updateand observe which specific repository URL is being fetched immediately prior to the post-invoke failure. - If a third-party PPA is responsible, navigate to the sources directory:
cd /etc/apt/sources.list.d/ - List the active PPA files:
ls -lh - Remove the offending PPA file (for example,
sudo rm problem-ppa.list). - Alternatively, remove it using the add-apt-repository utility:
sudo add-apt-repository --remove ppa:author/name
Reinstall and Update Core AppStream Packages
If the appstreamcli binary itself has encountered shared library corruption, reinstalling the core package restores fresh binaries.
- Reinstall the AppStream packages and shared libraries:
sudo apt install --reinstall appstream libappstream5(On newer Ubuntu releases like 24.04, the library package name may be
libappstream4orlibappstream5). - Reconfigure pending system packages:
sudo dpkg --configure -a - Fix any broken package dependencies:
sudo apt --fix-broken install
Disable the AppStream Post-Invoke Hook Temporarily
If you are operating a headless Ubuntu server that does not require graphical software stores, you can safely disable the post-invoke hook to allow apt update to run cleanly.
- Open the AppStream APT hook configuration in a terminal editor:
sudo nano /etc/apt/apt.conf.d/50appstream - Locate the line beginning with:
APT::Update::Post-Invoke-Success { ... }; - Comment out the line by placing two forward slashes (
//) or a hash symbol (#) at the start of the line:// APT::Update::Post-Invoke-Success {"if /usr/bin/test -w /var/cache/appstream; then /usr/bin/appstreamcli refresh-cache > /dev/null; fi";}; - Save and exit nano (Ctrl + O, Enter, Ctrl + X).
Verify Full APT and Software Store Operation
After repairing the cache and testing the configuration, verify that package management operates without warnings.
- Update your local package lists:
sudo apt update - Confirm that the update concludes with “All packages are up to date” without displaying any red post-invoke error messages.
- Launch the Ubuntu Software centre to ensure software listings, icons, and categories load smoothly.