Debian中关于apt配置文件sources.list

本文详细解析了Debian系统中apt配置文件sources.list的作用及格式。介绍了如何通过修改此文件更换软件源,以及如何添加定制源。同时,阐述了sources.list条目中各项参数的意义,包括归档类型、仓库地址、发行版本和软件包分类。

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

Debian中关于apt配置文件sources.list

在我们需要更换apt源的时候,需要修改/etc/apt/source.list这个文件,这篇文章就是来简单的解释一下这个文件的作用和含义


/etc/apt/sources.list是干什么用的

  • /etc/apt/sources.list是包管理工具 apt 所用的记录软件包仓库位置的配置文件,同样的还有位于/etc/apt/sources.list.d/*.list的各文件
  • apt从一个或多个软件仓库/源(sources)下载软件包并将其安装到计算机上,而apt软件源的主要配置文件(main Apt sources configuration file)就是/etc/apt/sources.list,一般在此文件中修改或添加官方的软件源, 更新后使用命令:apt-get update更新一下软件源
  • 如果用户想要添加定制源(第三方源),最好在/etc/apt/sources.list.d/下创建单独的文件, 只需“扩展名”为list即可, 更新后使用命令:apt-get update更新一下软件源

sources.list 条目格式

sources.list 文件中的条目一般都有如下所示的形式:

deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3

我树莓派上的source.list如下:

deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

档案类型 (Archive type)

每行的第一个单词deb或deb-src指示归档的类型:

  • deb表示归档文件包含二进制软件包(deb), 也就是我们通常使用的预编译软件包
  • deb-src指示源软件包,它是程序的源码以和Debian控制文件(.dsc)以及文件diff.gz。文件diff.gz包含了打包程序所需的更改

仓库地址 (Repository URL)

每行的第二个条目是软件包仓库的URL,apt用它来下载软件。可以更换仓库地址为其他地理位置更靠近自己的镜像来提高下载速度。

发行版本 (Distribution)

"发行版"可以分别是发行版代号或别名(jessie、stretch、buster、sid)或发行版类(release class)(oldstable、stable、testing、unstable)

Debian发行版本以"玩具总动员"电影中的角色命名, 目前(写博客的这段时间内,Debian 最新的稳定版版本是10.3), 发行版别名和发行版类对应情况是:

发行版别名发行版类
Jessieoldoldstable
Stretcholdstable
Busterstable
Bullseyetesting
Sidunstable

软件包分类 (Component)

跟在发行版之后的就是软件包的具体分类了,可以有一个或多个

  • main, 包含符合 DFSG 指导原则的自由软件包,而且这些软件包不依赖不符合该指导原则的软件包。这些软件包被视为 Debian 发型版的一部分
  • contrib, 包含符合 DFSG 指导原则的自由软件包,不过这些软件包依赖不在 main 分类中的软件包
  • non-free, 包含不符合 DFSG 指导原则的非自由软件包
  • 其他, 比如在我的树莓派上的source.list中出现了rpi这个分类

需要哪些分类,就把分类写道发行版本后面,在我的树莓派上的source.list上,就表明了开源和不开源的软件包都需要, 并且还多了rpi分类的软件包


参考资料

linux-debian软件安装包sources.list 路径 /etc/apt # deb cdrom:[Debian GNU/Linux 8.2.0 _Jessie_ - Official amd64 CD Binary-1 20150906-11:13]/ jessie main # deb cdrom:[Debian GNU/Linux 8.2.0 _Jessie_ - Official amd64 CD Binary-1 20150906-11:13]/ jessie main # deb http://ftp.debian.org/debian/ experimental main deb http://mirrors.ustc.edu.cn/debian/ jessie main contrib non-free deb-src http://mirrors.ustc.edu.cn/debian/ jessie main contrib non-free deb http://mirrors.ustc.edu.cn/debian/ jessie-proposed-updates main contrib non-free deb-src http://mirrors.ustc.edu.cn/debian/ jessie-proposed-updates main contrib non-free deb http://mirrors.ustc.edu.cn/debian/ jessie-updates main contrib non-free deb-src http://mirrors.ustc.edu.cn/debian/ jessie-updates main contrib non-free # deb http://mirrors.163.com/debian/ jessie main non-free contrib # deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib # deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib # deb-src http://mirrors.163.com/debian/ jessie main non-free contrib # deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib # deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib # deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib # deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib # deb http://cs3.swfu.edu.cn/debian/ jessie main contrib non-free # Line commented out by installer because it failed to verify: # deb http://security.debian.org/ jessie/updates main # Line commented out by installer because it failed to verify: # deb-src http://security.debian.org/ jessie/updates main # jessie-updates, previously known as 'volatile' # A network mirror was not selected during install. The following entries # are provided as examples, but you should amend them as appropriate # for your mirror of choice. # deb http://ftp.debian.org/debian/ jessie-updates main # deb-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值