mc.lcx@raspberrypi:~ $ sudo apt clean sudo apt autoclean sudo apt update Reading package lists... Done Building dependency tree... Done Reading state information... Done Hit:1 http://raspbian.raspberrypi.com/raspbian bookworm InRelease Hit:2 http://archive.raspberrypi.com/debian bookworm InRelease Reading package lists... Done Building dependency tree... Done Reading state information... Done 157 packages can be upgraded. Run 'apt list --upgradable' to see them. W: http://raspbian.raspberrypi.com/raspbian/dists/bookworm/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
时间: 2025-07-13 15:33:20 浏览: 20
### 解决 Raspberry Pi 系统中 APT 警告信息及软件包升级问题
在运行 `apt update` 时出现的警告信息:“Key is stored in legacy trusted.gpg keyring”表明系统仍在使用旧版的密钥管理方式,即通过 `/etc/apt/trusted.gpg` 存储信任的仓库密钥。APT 建议迁移到基于文件的密钥存储机制,每个仓库源应拥有独立的 `.gpg` 密钥文件,并存放在 `/etc/apt/trusted.gpg.d/` 目录下[^1]。
为了解决该警告并顺利升级系统中的 157 个可更新软件包,建议采取以下措施:
#### 更新软件源配置并替换为国内镜像
默认的官方源可能访问速度较慢或存在同步延迟,影响依赖解析和升级过程。可以编辑 `/etc/apt/sources.list` 文件,将原内容替换为国内稳定镜像地址,例如清华大学提供的 Debian 镜像[^3]:
```
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
deb https://security.debian.org/debian-security bookworm-security main contrib non-free
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free
```
同时,对于 Raspberry Pi 设备,还需要修改 `/etc/apt/sources.list.d/raspi.list` 文件,将其替换为清华源地址:
```
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main
```
此操作有助于提升下载速度并减少因源不可达导致的依赖问题。
#### 清理 APT 缓存并重新获取仓库元数据
执行以下命令清除本地缓存并刷新最新的仓库信息:
```bash
sudo apt clean
sudo apt autoclean
sudo apt update
```
这一步可以确保后续操作基于最新且完整的软件包列表进行。
#### 迁移至新式密钥管理机制
首先,列出当前所有已导入的信任密钥:
```bash
apt-key list
```
根据输出结果,识别出与各仓库源对应的 GPG 密钥 ID,并分别导出为独立的 `.gpg` 文件:
```bash
apt-key export <KEY_ID> | gpg --dearmour -o /etc/apt/trusted.gpg.d/<repo-name>.gpg
```
完成迁移后,删除 `/etc/apt/trusted.gpg` 中的相关密钥条目或直接清空其内容,以避免重复信任。
#### 执行软件包升级
确认上述步骤完成后,运行以下命令进行系统升级:
```bash
sudo apt upgrade
```
如果提示有依赖冲突或损坏的软件包,可尝试使用 `aptitude` 工具进一步解析问题:
```bash
sudo apt install aptitude
sudo aptitude upgrade
```
该工具会提供多种解决方案供选择,如降级某些组件、移除冲突包等,从而帮助恢复系统的稳定性。
#### 可选:手动修复特定软件包问题
若部分软件包持续报错,可尝试单独卸载并重新安装:
```bash
sudo apt remove <package-name>
sudo apt install <package-name>
```
这种方式适用于解决个别不兼容或损坏的软件包。
---
阅读全文
相关推荐



















