sudo apt-get update 失败 的解决

一 报错情况1 及我的解决办法

参考了:执行sudo apt-get update失败的解决方案

1 报错情况

我的报错情况如下(借用了别人的,我之前使用的Ubuntu默认源,下面的报错使用的清华源)。

错误提示: 
忽略:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease 
忽略:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
忽略:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
忽略:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease
错误:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal Release   
  Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
错误:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates Release
  Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
错误:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports Release
  Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
错误:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security Release
  Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
正在读取软件包列表... 完成                                   
E: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
E: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
E: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
E: 仓库 “https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

Ubuntu的默认源有时候也是有用的,因而不要删除,Ubuntu20.04默认源source.list文件内容:ubuntu20.04 LTS系统默认源source.list文件

2 解决办法

我在Ubuntu 原 source.list文件 中加上了 阿里云的源 (Ubuntu 镜像),注意要找到适合自己Ubuntu版本的源,我是Ubuntu20.04,因而在其中选择如下内容:

阿里云 ubuntu 20.04(focal) 配置内容如下:

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

打开Ubuntu系统中的source.list文件,如下:

sudo gedit /etc/apt/sources.list

在默认内容前面加上 阿里云源的ubuntu 20.04(focal) 配置内容

更改并且保存后,再执行 sudo apt-get update 依然会有报错,这是因为原来的那些源链接还在,而他们依旧不能用。但是系统会自动选择可用的源链接去更新(比如阿里云 链接),最后更新成功。可以参考执行sudo apt-get update失败的解决方案来详细查看具体过程。

也可参考 Ubuntu20.04 | 更新软件源 sudo apt-get update 出现错误,将原来soure.list文件中内容全部删除,而只粘贴新的源链接(比如 中科大源)。

### 解决 `sudo apt-get update` 命令下载失败的方法 当遇到 `sudo apt-get update` 执行过程中出现下载失败的情况时,可以尝试以下几种常见解决方案。 #### 修改软件源地址 有时官方服务器可能由于网络原因导致连接不稳定。可以选择更稳定的国内镜像站点来替换默认的APT源列表文件 `/etc/apt/sources.list` 中的内容[^1]。例如阿里云、清华大学开源软件镜像站等提供的服务通常较为稳定快速。 #### 清理并重置 APT 缓存 通过清理旧缓存数据再重新初始化索引库的方式有助于排除部分因本地残留错误信息而引发的问题: ```bash sudo rm -rf /var/lib/apt/lists/* sudo mkdir -p /var/lib/apt/lists/partial sudo apt-get clean sudo apt-get update ``` #### 处理未授权或损坏 PPA 源 如果提示类似于“无法认证来自该源的数据”的警告,则可能是某些第三方PPA仓库缺乏有效签名验证所致。对于不再需要使用的PPA可以直接移除;而对于希望保留下来的可信资源则应确保其公钥已正确导入系统内[^2]。 - 移除不必要的PPA: ```bash sudo add-apt-repository --remove ppa:<ppa_name> ``` - 添加缺失密钥(假设GPG key ID为`KEYID`): ```bash wget -qO - https://example.com/key.asc | gpg --dearmor | sudo tee /usr/share/keyrings/<repo-name>.gpg >/dev/null echo "deb [signed-by=/usr/share/keyrings/<repo-name>.gpg] http://ppa.launchpad.net/example/ppa/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/example-ubuntu-ppa.list ``` 以上措施能够帮助改善大多数情况下由不同因素引起的更新操作异常状况。值得注意的是,在实施任何更改之前建议先备份原始配置文件以防万一出现问题便于恢复原状。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值