Ubuntu学习之apt-get update 升级错误

本文详细记录了解决Ubuntu系统中使用apt-get更新时遇到的错误过程,包括删除损坏的包列表、重建tmp目录并调整权限,最终解决了更新时的临时文件创建失败和GPG验证问题。

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

今天在使用 apt-get update 时报错了

Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease [247 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease [107 kB]
0% [1 InRelease gpgv 247 kB] [Waiting for headers]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_Ign:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease
0% [2 InRelease gpgv 107 kB] [Waiting for headers]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_Ign:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease [109 kB]
0% [3 InRelease gpgv 109 kB]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-updates_InReleaIgn:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease [260 kB]
0% [4 InRelease gpgv 260 kB]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-proposed_InReleIgn:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease [107 kB]
0% [5 InRelease gpgv 107 kB]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-backports_InRelIgn:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease
Reading package lists... Error!
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Couldn't create temporary file to work with /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial_Release - mkstemp (2: No such file or directory)
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Couldn't create temporary file to work with /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-security_Release - mkstemp (2: No such file or directory)
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Couldn't create temporary file to work with /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-updates_Release - mkstemp (2: No such file or directory)
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Couldn't create temporary file to work with /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-proposed_Release - mkstemp (2: No such file or directory)
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Couldn't create temporary file to work with /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-backports_Release - mkstemp (2: No such file or directory)
E: Couldn't create temporary file to work with /var/lib/apt/lists/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial_Release - mkstemp (2: No such file or directory)
E: The package lists or status file could not be parsed or opened.

然后试着用以下指令

1 sudo rm /var/lib/apt/lists/* -vf
2 sudo apt-get update

具体解决:
run these two commands and it should get you fixed up.
Code:
sudo rm /var/lib/apt/lists/* -vf
The first command will remove the damaged list and when you run the second command it will replace it with a new list.

Code:
sudo apt-get update

然后突然想到前天被矿机坑过,我把tmp 文件夹给删了
重新新建了tmp 文件夹后,再试试

Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease [247 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease [107 kB]
0% [1 InRelease gpgv 247 kB] [2 InRelease 55.0 kB/107 kB 52%]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubIgn:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease [260 kB]
0% [2 InRelease gpgv 107 kB] [4 InRelease 110 kB/260 kB 42%]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuIgn:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease
0% [3 InRelease gpgv 109 kB] [4 InRelease 210 kB/260 kB 80%]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuIgn:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease [107 kB]
0% [4 InRelease gpgv 260 kB] [5 InRelease 62.1 kB/107 kB 58%]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubIgn:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease
0% [5 InRelease gpgv 107 kB]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/mirrors.cloud.aliyuncs.com_ubuntu_dists_xenial-backports_InRelIgn:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease
Fetched 830 kB in 0s (8,379 kB/s)
Reading package lists... Done
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-proposed InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://mirrors.cloud.aliyuncs.com/ubuntu xenial-backports InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.

结果好了一点儿,现在证书又有问题了 。。。。。。。。。。。。。

其实这个是由于新建的 tmp 文件夹权限不够的原因

chmod 777 /tmp

apt-get update --allow-unauthenticated
Ubuntu 20.04 系统中,`sudo apt-get update` 是用于更新软件包列表的常用命令。该命令会从配置的源地址下载最新的软件包信息,确保系统能够获取到可用的更新和安装包。如果执行过程中遇到问题,可以从以下几个方面进行排查和解决: 1. **网络连接问题** 确保系统具备正常的互联网访问能力。可以通过 `ping google.com` 或 `curl http://archive.ubuntu.com` 来测试网络是否通畅。 2. **源地址配置错误或失效** 某些第三方源(如 Docker 的源)可能已失效或被移除,导致更新失败。可以尝试删除相关源文件后重试: ```bash $ cd /etc/apt/sources.list.d/ $ sudo rm -f docker.list $ sudo rm -f docker.list.save $ sudo apt update ``` 此方法适用于清理无效源[^2]。 3. **无法认证数据源的问题** 如果提示“没有数字签名”或“无法认证来自该源的数据”,可能是由于某些 PPA 源未正确签名或密钥缺失。可以尝试添加缺失的 GPG 密钥,或者直接禁用相关源。 4. **更换镜像源** 如果默认的官方源访问不稳定,可将 `/etc/apt/sources.list` 中的源地址更改为国内镜像源,例如阿里云、清华源等: ```bash deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse ``` 5. **清除缓存并重新更新** 清理 APT 缓存可能会解决部分因缓存损坏导致的问题: ```bash $ sudo apt clean $ sudo apt autoclean $ sudo apt update ``` 6. **时间与时区设置异常** 若系统时间不准确,可能导致 SSL/TLS 认证失败。使用以下命令同步时间: ```bash $ sudo timedatectl set-ntp true ``` 7. **SSL/TLS 证书问题** 在某些代理环境或企业网络下,HTTPS 请求可能因证书链不完整而失败。可以临时禁用 HTTPS 校验(仅限排查问题): ```bash $ sudo apt-get update -o Acquire::http::No-Cache=true -o Acquire::http::MaxTries=5 ``` ### 示例:正常执行 `apt-get update` ```bash $ sudo apt-get update Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB] Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Fetched 379 kB in 2s (211 kB/s) Reading package lists... Done ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值