ubuntu系统手动换源解决 “Failed to download repository information”

该博客指导如何在Ubuntu系统中进入apt目录,并检查编辑权限。通过修改sources.list文件,将软件源替换为阿里云镜像,以加速软件包的下载和更新。详细步骤包括替换多个deb和deb-src行,并在完成更换源后执行sudo apt-get update和sudo apt-get upgrade来更新系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 进入apt目录下
	cd /etc/apt/
  1. 查看是否有修改文件的权限
  2. 使用vim修改source
	vi sources.list

更换阿里源(根据个人喜好)

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  1. 更新源
	sudo apt-get update 
	sudo apt-get upgrade
sudo apt update && sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common Hit:1 https://mirrors.aliyun.com/debian bookworm InRelease Ign:2 https://download.docker.com/linux/debian bookworm InRelease Hit:3 https://mirrors.aliyun.com/debian-security bookworm-security InRelease Hit:4 https://mirrors.aliyun.com/debian bookworm-updates InRelease Hit:5 https://mirrors.aliyun.com/debian bookworm-backports InRelease Ign:2 https://download.docker.com/linux/debian bookworm InRelease Ign:2 https://download.docker.com/linux/debian bookworm InRelease Hit:2 https://download.docker.com/linux/debian bookworm InRelease Err:2 https://download.docker.com/linux/debian bookworm InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 Reading package lists... Done Building dependency tree... Done Reading state information... Done All packages are up to date. W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://download.docker.com/linux/debian bookworm InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 W: Failed to fetch https://download.docker.com/linux/debian/dists/bookworm/InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8 W: Some index files failed to download. They have been ignored, or old ones used instead. W: Target Packages (stable/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_debian-bookworm.list:1 and /etc/apt/sources.list.d/docker.list:1 W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_debian-bookworm.list:1 and /etc/apt/sources.list.d/docker.list:1
03-12
<think>嗯,用户遇到了在Ubuntu系统安装Docker时出现的GPG签名验证错误,具体是缺少公钥7EA0A9C3F273FCD8。我需要帮他们解决这个问题。首先,我应该回忆一下处理这类问题的常见方法。 记得当系统更新时,如果添加了第三方仓库,可能需要导入他们的GPG密钥,否则会提示没有公钥的错误。用户提供的引用中有提到几种解决方案,比如手动添加密钥或者删除有问题的仓库配置。 第一种方法是使用apt-key命令手动添加密钥。虽然现在apt-key已经被废弃了,但在旧的系统中可能仍然有效。用户引用5中提到了这个方法,执行sudo apt-key adv命令,指定密钥服务器和密钥ID。成功后应该能解决问题。 不过现在更推荐的方法是将密钥直接添加到/etc/apt/trusted.gpg.d/目录中,使用gpg --export导出并保存。或者使用add-apt-repository命令,但不确定是否适用于Docker的仓库。 另一种方法是临时删除有问题的仓库文件,如引用3中的解决方案,进入/etc/apt/sources.list.d/目录,删除docker.list文件,然后更新。但这样可能无法安装Docker,所以可能只是临时措施。 用户的问题在于缺少公钥,所以正确的方法应该是导入这个密钥。除了手动添加外,还可以通过下载密钥文件并添加到信任列表中。比如使用curl下载密钥,然后用gpg处理,最后复制到对应的目录。 另外,需要检查用户的系统版本是否正确,比如Ubuntu版本是否匹配Docker仓库的版本。错误信息中提到的是bionic,也就是Ubuntu 18.04,但用户可能是在20.04上操作,导致仓库不兼容,从而引发问题。这时候需要确认仓库配置中的发行版名称是否正确。 总结下来,步骤应该是:首先尝试手动导入密钥,如果不行,检查仓库配置是否正确,或者删除仓库后重新添加。同时,要提醒用户注意系统版本与仓库的兼容性。</think>### 解决方案:Docker仓库GPG公钥验证失败问题 #### 问题原因 在Debian/Ubuntu系统中,当使用`apt update`更新软件源时,若第三方仓库(如Docker)未正确配置GPG公钥,会导致签名验证失败,错误提示`NO_PUBKEY 7EA0A9C3F273FCD8`[^2][^4]。这是因为系统无法验证该仓库的软件包合法性。 --- #### 逐步解决方法 ##### 方法1:手动添加缺失的公钥 1. **通过`apt-key`直接添加密钥(适用于旧系统)** 运行以下命令从Ubuntu密钥服务器获取公钥: ```bash sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8 ``` 成功后,系统会显示`gpg: imported: 1`,表示密钥已导入[^5]。 随后执行更新: ```bash sudo apt update ``` 2. **通过`gpg`手动添加密钥(推荐新系统)** Debian 11+/Ubuntu 20.04+已弃用`apt-key`,需将密钥保存到`/etc/apt/trusted.gpg.d/`: ```bash sudo gpg --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8 sudo gpg --export --armor 7EA0A9C3F273FCD8 | sudo tee /etc/apt/trusted.gpg.d/docker-ce.asc sudo apt update ``` --- ##### 方法2:修复仓库配置 若密钥添加后仍报错,可能是仓库地址与系统版本不兼容(如Ubuntu 20.04误用`bionic`仓库)[^3]: 1. **删除错误仓库配置** ```bash sudo rm /etc/apt/sources.list.d/docker*.list ``` 2. **重新添加正确的仓库** 参考Docker官方文档,使用与系统版本匹配的仓库名称(如`focal`对应Ubuntu 20.04): ```bash sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` 3. **再次更新** ```bash sudo apt update ``` --- ##### 方法3:临时跳过验证(不推荐) 若仅需临时修复,可禁用签名验证(存在安全风险): ```bash sudo apt update --allow-insecure-repositories ``` --- #### 验证解决 执行`sudo apt update`后,若不再提示`NO_PUBKEY`错误且能正常拉取Docker仓库数据,则问题已解决[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SimpleZihao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值