E: Problem executing scripts APT Update::Post-Invoke-Success error during apt-get update

I cannot install any package.
It seems the command apt-get update must be run
but it throws some errors:

$ sudo apt-get update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]     
Hit:2 http://ve.archive.ubuntu.com/ubuntu xenial InRelease                     
Hit:3 http://ve.archive.ubuntu.com/ubuntu xenial-updates InRelease             
Hit:4 http://ve.archive.ubuntu.com/ubuntu xenial-backports InRelease           
Fetched 102 kB in 23s (4337 B/s)                                               
*** Error in `appstreamcli': double free or corruption (fasttop): 0x000000000210f4b0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fac8d8317e5]
[...]
Aborted (core dumped)
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 
 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; 
 then appstreamcli refresh > /dev/null; fi'
E: Sub-process returned an error code

Full terminal output.txt

Asked By: Shirley Temple

||

This worked for me
(From here, https://forum.siduction.org/index.php?topic=6174.0):

sudo apt-get purge libappstream3
Answered By: Max Robbertze
sudo apt install --reinstall libappstream3

can fix it.

Answered By: FourDollars

In my case, purging, or re-installing didn’t help.

The removal of the apt.conf.d entry did however solve the issue for me.

Friday 25 August  22:17:45 AEST 2017
LSB Version:    core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:printing-9.20160110ubuntu0.2-amd64:printing-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
    Distributor ID: Ubuntu
    Description:    Ubuntu 16.04.3 LTS
    Release:    16.04
    Codename:   xenial

I ran the following commands to get rid of the error:

sudo apt-get purge libappstream2
sudo rm /etc/apt/apt.conf.d/50appstream
Answered By: AlienResidents

I came from this page and was redirected here, over there I cannot answer but this is actually an answer for that page. Since I had the same issue (at least same as one of the related issues, but hey I did not relate them so sorry if it is not right solution for you ) and found it quite difficult to find the right information, but in the end succeeded, I thought why not share it here. It took me 2 days evening hours to put the pieces together but this is what I did, hope it helps some of you.

I followed this procedure to clean the mess, made a backup first, just in case.

sudo apt install appstream/xenial-backports
sudo rm /etc/apt/apt.conf.d/50appstream
sudo rm /var/cache/app-info/xmls/fwupd.xml
sudo apt install --reinstall libappstream4
sudo appstreamcli refresh --force
sudo reboot

Not sure if the reboot is necessary but after reboot I did:

sudo appstreamcli refresh --force

and had no more errors.

Answered By: Marcellus

For having this:

$ sudo apt-get update
[sudo] password for XXX:           
...

AppStream system cache was updated, but problems were found: Metadata files have errors: /var/cache/app-info/xmls/fwupd.xml
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; then appstreamcli refresh-cache > /dev/null; fi'
E: Sub-process returned an error code

$ sudo appstreamcli --version
AppStream CLI tool version: 0.10.6

$ sudo appstreamcli refresh-cache --force --verbose
** (appstreamcli:15334): DEBUG: Added /usr/share/app-info/xmls to metadata search path.
** (appstreamcli:15334): DEBUG: Added /var/lib/app-info/yaml to metadata search path.
** (appstreamcli:15334): DEBUG: Added /var/cache/app-info/xmls to metadata search path.
** (appstreamcli:15334): DEBUG: Refreshing AppStream cache
** (appstreamcli:15334): DEBUG: Searching for data in: /usr/share/app-info/xmls
** (appstreamcli:15334): DEBUG: Searching for data in: /var/cache/app-info/xmls
** (appstreamcli:15334): DEBUG: Searching for data in: /var/lib/app-info/yaml
** (appstreamcli:15334): DEBUG: Reading: /usr/share/app-info/xmls/org.freedesktop.fwupd.xml
** (appstreamcli:15334): DEBUG: Reading: /var/cache/app-info/xmls/fwupd.xml
** (appstreamcli:15334): DEBUG: WARNING: Could not parse XML data: Entity: line 265: parser error : EntityRef: expecting ';'
        <checksum filename="Firmware_SF30&SN30_Pro_V1.26.dat" target="content" t
                                                            ^
...

The fix is:

$ sudo -i

# cd /var/cache/app-info/xmls/

# ls -l
total 236
drwxr-xr-x 2 root root   4096 jul 27 09:56 ./
drwxr-xr-x 5 root root   4096 aug 31  2017 ../
-rw-r--r-- 1 root root 233177 jun 29 16:02 fwupd.xml

# sed < fwupd.xml  -rne 's/Firmware_SF30&SN30_Pro_V1.26.dat/Firmware_SF30&SN30_Pro_V1.26.dat/gp'
        <checksum filename="Firmware_SF30&SN30_Pro_V1.26.dat" target="content" type="sha1">3ef2bdee8aca2a45b9f53b4d4cce9722523f57f8</checksum>

# sed fwupd.xml -i_BACKUP -re 's/Firmware_SF30&SN30_Pro_V1.26.dat/Firmware_SF30&SN30_Pro_V1.26.dat/gp'

# ls -l
total 464
drwxr-xr-x 2 root root   4096 jul 27 09:57 ./
drwxr-xr-x 5 root root   4096 aug 31  2017 ../
-rw-r--r-- 1 root root 233328 jul 27 09:57 fwupd.xml
-rw-r--r-- 1 root root 233177 jun 29 16:02 fwupd.xml_BACKUP

# rm fwupd.xml_BACKUP

# apt-get update
Hit:1 http://se.archive.ubuntu.com/ubuntu xenial InRelease
...
Fetched 491 kB in 0s (715 kB/s)                    
Reading package lists... Done

# exit
logout

$

Note:
https://github.com/hughsie/lvfs-website/issues/33

Answered By: Hannu

I had this issue after upgrading from 16.04 LTS to 18.04.1 LTS. My initial error message was:

AppStream system cache was updated, but problems were found: Metadata files have errors: /var/cache/app-info/xmls/fwupd.xml

Here is what I did to fix it:

$ sudo rm /var/cache/app-info/xmls/fwupd.xml
$ sudo appstreamcli refresh --force

That resulted in this terminal message:

AppStream cache update completed successfully.

Then, sudo apt-get update and sudo apt-get upgrade worked perfectly.

Answered By: christopherbalz

A working solution in 18.04.1 is to install appstream and libappstream4 manually from the Cosmic repos; pick your architecture and a mirror, download, install with dpkg -i, then try appstreamcli refresh --force.

Answered By: arielCo

Ubuntu 18.04 and later

In Ubuntu 18.04 and later open the terminal and type:

sudo apt install --reinstall libappstream4

You can also test the above command before running it without making any changes to your system (so sudo is not required).

apt install --reinstall --simulate libappstream4
Answered By: karel
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.