Linux – Errors when updating package list with apt-get on (K)ubuntu

linuxpackage-managementUbuntuubuntu 12.04updates

I get some errors when trying to update the package list with sudo apt-get update command, specifically the error messages are as follows:

W: GPG error: http://dl.google.com stable Release: The following signatures were invalid: BADSIG A040830F7FAC5991 Google, Inc. Linux Package Signing Key 
W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://archive.canonical.com precise Release: The following signatures were invalid: BADSIG 40976EAF437D05B5 Ubuntu Archive Automatic Signing Key 

W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://extras.ubuntu.com precise Release: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key 

W: Failed to fetch http://archive.canonical.com/ubuntu/dists/precise/Release  

W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/precise/Release  

W: Some index files failed to download. They have been ignored, or old ones used instead.

I'm using Kubuntu 12.04.

EDIT
I performed the commands suggested by terdon in his answer, but it still doesn't work; when trying to update the keys, I got the following output:

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.OE3Vb6NDgl --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com A040830F7FAC5991
gpg: requesting key 7FAC5991 from hkp server keyserver.ubuntu.com
gpg: key 7FAC5991: "Google, Inc. Linux Package Signing Key " not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.QFmVRIYHrE --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com 40976EAF437D05B5
gpg: requesting key 437D05B5 from hkp server keyserver.ubuntu.com
gpg: key 437D05B5: "Ubuntu Archive Automatic Signing Key " not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.kJGIgNoOEW --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com 16126D3A3E5C1192
gpg: requesting key 3E5C1192 from hkp server keyserver.ubuntu.com
gpg: key 3E5C1192: "Ubuntu Extras Archive Automatic Signing Key " not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

And trying to use sudo apt-get update still gives me the same errors as before.

Best Answer

You will need to import the correct GPG keys for each repository. So, for each missing key, run this command:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com KEY

In your case, you are missing the keys for A040830F7FAC5991, 40976EAF437D05B5 and 16126D3A3E5C1192, you can get all three by running:

for key in A040830F7FAC5991 40976EAF437D05B5 16126D3A3E5C1192; do 
 sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com $key; done

After running this command, try sudo apt-get update again and it should work perfectly well.


Update, I was assuming that reimporting the keys would fix them, it looks like that did not work. Try this instead (source):

sudo apt-get clean
sudo mv /var/lib/apt/lists /var/lib/apt/lists.old 
sudo mkdir -p /var/lib/apt/lists/partial
sudo apt-get clean
sudo apt-get update
Related Question