在ubuntu中运行apt-get update时,有时会出现如下报错
ubuntu@ubuntu-virtual-machine:~$ sudo apt update
[sudo] password for ubuntu:
Get:1 http://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:2 http://packages.microsoft.com/repos/code stable InRelease
Err:1 http://dl.google.com/linux/chrome/deb stable InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4EB27DB2A3B88B8B
Hit:3 http://id.archive.ubuntu.com/ubuntu bionic InRelease
Hit:4 http://id.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://id.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:6 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:7 http://packages.ros.org/ros/ubuntu bionic InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
468 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://dl.google.com/linux/chrome/deb stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4EB27DB2A3B88B8B
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4EB27DB2A3B88B8B
W: Some index files failed to download. They have been ignored, or old ones used instead.
如果不去解决,无法继续进行后续的升级操作
ubuntu@ubuntu-virtual-machine:~$ sudo apt upgrade
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
这是由apt包系统的安全机制引起的问题,有时系统无法包含所有的key。此处有快速修复的办法,即将缺少的key加进去即可。
观察里面的报错,其实是4EB27DB2A3B88B8B(请注意,每个人的KEY会不一样,所以需要从自己的报错信息中找出对应的值,替换到下面的指令,如果是多个key,相应的发送多条指令即可),这个key缺失,因此只要将其加入即可,可使用如下指令:
ubuntu@ubuntu-virtual-machine:~$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
Executing: /tmp/apt-key-gpghome.6DtlfeE5p7/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
gpg: key 7721F63BD38B4796: "Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>" 1 new signature
gpg: key 7721F63BD38B4796: "Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>" 1 new subkey
gpg: key 7721F63BD38B4796: "Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>" 2 signatures cleaned
gpg: Total number processed: 1
gpg: new subkeys: 1
gpg: new signatures: 1
gpg: signatures cleaned: 2
后续即可正常进行升级操作