apt 软件源格式解析

写在前面

每次安装完 Ubuntu 的第一件事情就是给 apt 换源,而换源过程基本就是复制粘贴,今天突然发现自己复制粘贴这么久也不知道粘贴了什么,于是了解了一下并分享出来。总之就是一篇看了也没什么用的文章,了解一下而已。

正文

Linux 上有问题就先 man 一下,于是我 man apt,然后发现没有说关于 source.list 的格式,不过在手册的末尾最后发现有专门的文档讲解文件格式,于是 man source.list

其实 apt 源文件并不只有 source.list,也有一个叫 source.sources。两者的区别是格式不同。前者使用的格式称为 ONE-LINE-STYLE,也就是网上常见的一行一个的那种。后者使用的格式叫做 DEB822-STYLE,这种格式在网上应该比较少见。

ONE-LINE-STYLE

这种格式是最常见的了,通常从网上复制粘贴来的就是这个格式。下面是 Ubuntu 20.04 LTS 的默认源。

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
# deb-src http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security multiverse

下面是此风格的基本格式。

deb [ option1=value1 option2=value2 ] uri suite [component1] [component2] [...]
deb-src [ option1=value1 option2=value2 ] uri suite [component1] [component2] [...]
  • deb:表示从这里可以找到二进制程序,即包含已经编译好的程序。
  • deb-src:表示从这里找到源码。
  • option:表示额外的选项,比如 arch 表示体系结构,amd64 啥的。语法上不仅支持 option=value1 也支持 option=value1,value2option-=valueoption+=value+=-= 仅支持那些可能有多个值的选项。
  • uri:就是源的网址,比如腾讯的 apt 源的网址就是 http://mirrors.cloud.tencent.com/ubuntu/
  • suite:代表发行版的类型如 stable。也可以代表发行版的代号比如 Ubutnu 20.24 LTS 的代号就是 focal[3]所以说如果你用的是 Ubutnu 18.04,那么你应该写 bionic,因为这个版本的代号就叫 bionic[3]不过版本代号后面可能还会跟着如 -backports 这样的后缀,相关信息见 UbuntuUpdates – Community Help Wiki
  • component:表示软件包的分类,不同的 Linux 发行版有不同的分类。对于 Ubuntu 来说有下面的几种。
    • main:由 Canonical 支持的自由和开源软件。[1]
    • universe:由社区维护的自由和开源软件。[1]
    • restricted:设备驱动程序。[1]
    • multiverse:受版权或法律问题限制的软件。[1]

DEB822-STYLE

此格式从 apt 1.1 开始支持,文件必须以 .sources 结尾。下面是它的基本格式。

Types: deb deb-src
URIs: uri
Suites: suite
Components: [component1] [component2] [...]
option1: value1
option2: value2

Types: deb deb-src
URIs: uri
Suites: suite
Components: [component1] [component2] [...]
option1: value1
option2: value2

同一条目中的每个字段各占一行,不同的条目间用一行空行分隔。各个字段的含义与 ONE-LINE-STYLE 中的完全相同。你也可以通过添加一行 Enabled: no 来禁用某一个条目。如果一个字段有多个值则每个值之间用空格分隔。

例子

下面的两种格式的源配置是等效的。

deb http://us.archive.ubuntu.com/ubuntu focal main restricted
deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://us.archive.ubuntu.com/ubuntu focal-updates main restricted
Types: deb
URIs: http://us.archive.ubuntu.com/ubuntu
Suites: focal focal-updates
Components: main restricted

Types: deb
URIs: http://security.ubuntu.com/ubuntu
Suites: focal-security
Components: main restricted

参考资料

本文作者:ADD-SP
本文链接https://www.addesp.com/archives/3406
版权声明:本博客所有文章除特别声明外,均默认采用 CC-BY-NC-SA 4.0 许可协议。
暂无评论

发送评论 编辑评论


上一篇
下一篇