03
2019
08

Ubuntu中sources.list文件详解

Ubuntu使用apt来管理软件包,apt可以将软件库存储在如下文件中:

/etc/apt/sources.list和/etc/apt/sources.list.d/目录中带.list后缀的文件中。可以使用命令man sources.list来查看apt的完整存储机制。通过编辑这些文件,我们可以添加、删除、或者临时关闭某些软件库。

注意:在更改上述文件之前,最好先备份一下。例如, sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

下面详细分析文件sources.list的格式和写法

1、以字符’#'开头的行代表该行是一行注释

2、不以’#'开头的行是apt repository,它的格式为:

1、deb: 二进制包仓库

2、、deb-src: 二进制包的源码库

3、URI:库所在的地址,可以是网络地址,也可以是本地的镜像地址

4、codename: Ubuntu版本的代号。可以用命令lsb_release -sc来查看当前系统的代号。

5、components: 软件的性质(free或non-free等)

详解 deb

deb后面的内容有三大部分:deb URI section1 section2

下面以deb http://us.archive.ubuntu.com/ubuntu/ trusty universe为例进行说明。

###URI: 库所在的地址

URI支持http,ftp,以及本地文件cdrom等路径。

我们访问实例的源路径:http://us.archive.ubuntu.com/ubuntu/   可以看到如下内容:

其中,比较重要的就是dists目录和pool目录。dists目录包含了当前库的所有软件包的索引。这些索引通过系统版本分类在不同的文件夹。

进入dists目录,看到如下内容:

可以看到很多文件夹,这些文件夹都是以下格式命名的:

codename

codename-backports

codename-proposed

codename-security

codename-updates

其中codename就是Ubuntu不同版本的代号,上图中的文件夹名其实就是对应了deb后面的section1。

可以看到Ubuntu14.04版本对应的代号是trusty。上述文件夹的差别在于:

Security - Important Security Updates.

Updates - Recommended Updates.

Proposed - Pre-released Updates.

Backports - Unsupported Updates.

因此我们可以根据需要填写不同的section1。

打开上面的任意一个文件夹,可以看到如下内容:

有main, multiverse, restricted, universe文件夹,这些文件夹名其实对应deb后面的section2。这些文件夹里面包含了不同软件包索引。这几个文件夹内包的区别在于:

main: 完全的自由软件。

restricted: 不完全的自由软件。

universe: Ubuntu官方不提供支持与补丁,全靠社区支持。

multiverse:非自由软件,完全不提供支持和补丁。

如果我们打开main目录下的binary-i386子目录下的Packages.gz文件,可以看到如下内容:

Package: flashplugin-downloader

Architecture: i386

Version: 29.0.0.171ubuntu0.17.10.1

Multi-Arch: foreign

Priority: optional

Section: multiverse/web

Source: flashplugin-nonfree

Origin: Ubuntu

Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>

Original-Maintainer: Bart Martens <bartm@knars.be>

Bugs: https://bugs.launchpad.net/ubuntu/+filebug

Installed-Size: 25

Depends: flashplugin-installer (>= 11.1.102.55ubuntu3)

Filename: pool/multiverse/f/flashplugin-nonfree/flashplugin-downloader_29.0.0.171ubuntu0.17.10.1_i386.deb

Size: 1894

MD5sum: a25f9bd19b8c6b4247e7b4f556f96eb5

SHA1: 08358cfd6a59f7724ef6fab66dc0cfabe4792c17

SHA256: 0ee2d3fa22cd37e80cd9180b5795c7dc8ac5de942b23c56252fde31276b93fe1

Homepage: http://www.adobe.com/products/flashplayer.html

Description: Adobe Flash Player plugin installer (transitional package)

Description-md5: 66ea91f4e504085408ea841953dc65d0

......

说明: Packages.gz这个文件其实是一个“索引”文件,里面记录了各种包的包名Package、运行平台(Architecture)、版本号(Version)、依赖关系(Depends)、deb包地址(Filename)等 。注意到Filename指向的是源服务器pool目录下的某个deb。因此我们可以猜测,apt-get install 某个软件时,其实就是基于这些Packages.gz来计算依赖关系,然后根据其中的Filename地址来下载所需的deb,然后再执行dpkg -i xxx.deb来完成软件包的安装。

注意:修改sources.list之后需要执行命令sudo apt-get update

Ubuntu的官方库地址:https://launchpad.net/ubuntu/+archivemirrors

Ubuntu中国的官方地址:http://mirrors.aliyun.com/ubuntu/

经过上面分析,比如Ubuntu18,04的sources.list可以写成如下格式:

deb http://mirrors.aliyun.com/ubuntu bionic main multiverse restricted universe

deb http://mirrors.aliyun.com/ubuntu bionic-updates main multiverse restricted universe

deb http://mirrors.aliyun.com/ubuntu bionic-security main multiverse restricted universe

deb http://mirrors.aliyun.com/ubuntu bionic-proposed main multiverse restricted universe

deb http://mirrors.aliyun.com/ubuntu bionic-backports main multiverse restricted universe

作者:VinQin 

来源:CSDN 

本文转载:https://blog.csdn.net/u012843189/article/details/80964287 

原文链接:https://www.qiquanji.com/post/8211.html

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注

更新实时通知

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。