You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian 12中apt-add-repository无法添加non-free组件的解决方案咨询

在Debian 12中使用apt-add-repository添加non-free组件无效的替代解决方案

问题描述

在Debian 12(bookworm)中执行apt-add-repository -y non-free命令添加non-free组件时,命令输出提示已添加组件,但/etc/apt/sources.list.d/debian.sources文件并未更新,组件未成功添加。该操作在Debian 11(bullseye)中可正常执行,原因是Debian 12采用了新的Deb822格式源文件(.sources),替代了旧的sources.list格式:

旧格式:

deb http://deb.debian.org/debian/ bookworm main

新格式:

Types: deb
# http://snapshot.debian.org/archive/debian/20230703T000000Z
URIs: http://deb.debian.org/debian
Suites: bookworm bookworm-updates
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

相关操作及输出如下:

# apt-get update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian bookworm-updates InRelease
Hit:3 http://deb.debian.org/debian-security bookworm-security InRelease
Reading package lists... Done
# apt-add-repository -y non-free
Adding component(s) 'non-free' to all repositories.
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian bookworm-updates InRelease
Hit:3 http://deb.debian.org/debian-security bookworm-security InRelease
Reading package lists... Done
# cat /etc/apt/sources.list.d/debian.sources 
Types: deb
# http://snapshot.debian.org/archive/debian/20230703T000000Z
URIs: http://deb.debian.org/debian
Suites: bookworm bookworm-updates
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
# http://snapshot.debian.org/archive/debian-security/20230703T000000Z
URIs: http://deb.debian.org/debian-security
Suites: bookworm-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

替代解决方案(除手动编辑文件外)

1. 指定完整源条目调用apt-add-repository

直接执行包含non-free组件的完整源添加命令,系统会自动更新源配置文件:

# 添加主源及更新源的non-free组件
apt-add-repository -y "deb http://deb.debian.org/debian bookworm main non-free"
apt-add-repository -y "deb http://deb.debian.org/debian bookworm-updates main non-free"
# 添加安全源的non-free组件
apt-add-repository -y "deb http://deb.debian.org/debian-security bookworm-security main non-free"

执行完成后,再次运行apt-get update即可生效。

2. 使用apt edit-sources简化编辑

运行以下命令,系统会自动打开默认编辑器(如nano)并加载所有源配置文件:

apt edit-sources

在打开的文件中,找到对应源的Components行,添加non-free(例如Components: main non-free),保存并退出编辑器后,apt会自动刷新软件源缓存。


内容的提问来源于stack exchange,提问作者Milosz Wasilewski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 15:37:26