一、简介
APT(Advanced Package Tool)是linux的Debian发行版已经一些以Debian为基础的发行版(Ubuntu等)下,做软件包管理的一个工具,其中包括deselect和apt-get两个工具,他们都可以提供下载、安装、更新、删除软件包的功能。 安装包的过程分为下载和安装两个部分,当包下载完成后,dpkg将会接管来完成安装任务。
APT源,大致可以理解为一个数据库,里面记录了大大小小各种软件包的下载地址,APT安装完成后,有一个默认的源,也就是官方源,在ubuntu系统下,可以看到这些源的地址都是ubuntu.com等等。APT会选择把这个默认源中记录的各个软件包的索引缓存在本地,以后每次执行apt-get install时都会读取本地记录的内容寻找对应包的下载地址。但是时间一久,有的软件包可能换地址了,更新链接等等,此时就需要apt-get update从“源”获取最新的数据来更新本地的缓存。
由于APT官方提供的源在国外,国内访问会比较慢,所以很多人选择使用国内镜像,所谓镜像就是在国内的某个服务器上拷贝了一份和官方源完全相同的内容,阿里和中科大等等都有APT的国内镜像,这些镜像大约每5—10分钟就会和官方的源进行一次同步,因此实时性还是可以保证的。apt源的配置文件是/etc/apt/sources.list,每次执行apt-get update时,APT都会读取这个文件中的源的地址,并更新本地软件包索引的内容,用编辑器打开后直接修改即可(with sudo)。
二、常用命令
1、软件包搜索
APT可以提供模糊查询,例如:
sudo apt-cache search mysql
就可以查询到很多大大小小很多关键字或者简介中包含“mysql”的包。
2、查看本机已经安装的包
dpkg -l | grep mysql
3、软件包的安装、更新和卸载
sudo apt-get install package1
sudo apt-get remove package1
sudo apt-get upgrade package1
sudo apt-get purge package1
sudo apt-get autoremove
install的-d和-y选项
-d
全部能够正确下载时才开始安装,否则就终止;确认所有包都已经下载,再重新执行一次命令(不含-d),就可以全部安装了。
-y
不提示安装。
4、upgrade与dist-upgrade
apt-get upgrade命令会试图把package升级到最新的版本,但是前提是此过程中没有任何的其他包会被删除或者下载安装。即如果包A的旧版本升级后,A所依赖的包也和原来不同(包括版本不同)了,upgrade将会放弃更新A。
apt-get dist-upgrade则会智能的解决这个问题,它会升级A,并以最小的代价解决新的依赖的问题。即A的依赖也会因此被更新或者下载等等。
三、ubuntu系统更换源
更换源的方法非常简单:修改/etc/apt/sources.list文件即可
3.1:进入/etc/apt/
cd /etc/apt
3.2:修改sources.list文件
sudo vi sources.list (要有管理员权限)
3.3:可以在修改前先对 sources.list文件进行备份
sudo cp sources.list sources.list.bak
删掉sources.list的其他内容,任意选择一种源的内容复制粘贴进去,保存,例如,选择阿里源
3.4:更新APT
sudo apt-get update
四、Ubuntu各个版本的阿里云源内容
4.1:ubuntu16.04 LTS
4.1.1:阿里源:
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
4.1.2:东北大学:
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial main restricted #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial multiverse
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security multiverse
4.1.3:清华大学:
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
4.2:ubuntu 14.04 LTS
4.2.1:Ubuntu 官方更新服务器(欧洲,此为官方源,国内较慢,但无同步延迟问题,电信、移动/铁通、联通等公网用户可以使用):
deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
Ubuntu官方提供的其他软件(第三方闭源软件等):
deb http://archive.canonical.com/ubuntu/ trusty partner
deb http://extras.ubuntu.com/ubuntu/ trusty main
4.2.2:阿里云:
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
4.2.3:以下为有教育网接入的服务器(推荐教育网用户使用,部分非教育网用户也有可观的速度。教育网用户请优先使用IPv6地址。
中国科学技术大学更新服务器(位于合肥,千兆教育网接入,百兆电信/联通线路智能路由),由中科大Linux 用户协会和中科大学网络信息中心维护,包含其他开源镜像,Deepin 官方服务器 实际亦指向此处:
deb http://debian.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-backports main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-security main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe
IPv6-Only 地址
deb http://mirrors6.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors6.ustc.edu.cn/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors6.ustc.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors6.ustc.edu.cn/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors6.ustc.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://mirrors6.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe
deb-src http://mirrors6.ustc.edu.cn/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://mirrors6.ustc.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://mirrors6.ustc.edu.cn/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://mirrors6.ustc.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe
4.2.4搜狐更新服务器(山东联通千兆接入,官方中国大陆地区镜像跳转至此) ,包含其他开源镜像:
deb http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
4.2.5:网易163更新服务器(广东广州电信/联通千兆双线接入),包含其他开源镜像:
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
五、APT仓库目录分析
1.1 版本代号
sid,still in development,该版本和unstable版本是一样的。
版本可以从多个侧面来进行命名。
第一,从release的角度进行命名。比如,buster、jessie、stretch
第二,使用数字编码,比如7、8、9,然后还有小版本,7.11、8.9
第三,对于当前最新的开发版本,又可以命名为stable、unstable和testing分支,当前的unstable又可以叫做sid。
第四,同样的对于上一个开发版本,可以命名为oldstable、上上个版本,oldoldstable。
1.2 dists目录
这个里面即是各个版本的包仓库,如果当前的开发版本是stretch,那么stable目录是到stretch的软连接,其它的依次类推。
1.3 dists子目录
dists的子目录分为release和suite两大类,release即buster、jessie和stretch这些,而suite即unstable、testing和stable等。
再进一步的子目录又分为contrib、main和non-free。
再进一步的子目录里面是binary-xxx、source,binary-xxx 里面是对应二进制包的元数据,Packages.gz,source里面是对应的源码包的元数据,即Sources.gz。
通过它们可以找到真正的二进制包和源码包。
1.4 pool目录
真正的debian的二进制包和源码包是在根目录下面的这个pool目录下。
1.5 main、contrib和non-free
全部是free的包在main中,
全部是non-free的包在non-free中
依赖于non-free的包仔contrib中。
这些即是components
1.6 xxx-updates
proposed-updates里面的一些包也会放在这里。
1.7 xxx-proposed-updates
在稳定版的基础上的更新也会进行release,比如7.1、7.2、7.3等等,这些release被称为point release,而这个proposed-updates就是为下一次的point release做准备工作的,也就是说,对稳定版本的更新先放在proposed-updates里面,然后积累到了一定的量之后发布point release。
1.8 xxx-backports
就是同一个发行版的unstalble、testing中的包,在stable下重新编译,使之可以在stable版本下使用。
1.9 xxx-backports-sloppy
就是下一个发行版的unstalbe、testing中的包,在old stable下重新编译,使之可以在old stable版本下使用,比如stretch的tesing中的包,使之可以在jessie的stable中使用,就上传到这个文件夹里面。
1.10 xxx-kfreebsd
kfreebsd指的是使用freebsd kernel的debian发行版。
1.11 xxx-kfreebsd-proposed-updates
同xxx-proposed-updates
1.12 update的最小粒度是包吗?
这些不重要,重要的是,更新之后,所用的包就是新版本的包了。
2 debian开发的流水线
2.1 debian分支开发的顺序
unstable->testing->stable
debian的开发分支叫做unstabel/sid,当需求开发完,并且bug差不多了之后,会froze掉,进入testing分支,这个阶段只是修改bug,当bug解完了,进入下一个stable分支。
3 源
3.1 sources.list文件的结构
每个源占一行
deb是二进制包,deb-src是源码包
deb uri distribution [component1] [component2] [...]
distribution就是suite和release。
六 、debian repository 目录结构
下面是简化的Ubuntu源的目录结构。
NOTE:
所有的兄弟文件夹(父目录相同的文件夹)都只展开第一个
Pool文件夹的四个子文件夹里,存放的是按照字母顺序分类的各个软件包
每个repo的文件夹会有出入,实际以你使用的为准
重要的文件(夹)和解释
根目录下至少有两个文件夹:dists和pool。dists文件夹里存储的是关于软件包的信息数据,包括:文件名称、大小、位置、校验码等。而pool文件下是具体的软件包存放位置,单独把文件放在pool文件夹里是为了防止文件的重复。
Release/InReleas
文件位于$ARVHIVE_ROOT/dists/$DISCTRIBUTION 文件夹内,InRelease文件是内部自认证的,而Release文件需要伴随Release.gpg文件出现。这个文件包含该发布版(所在的文件夹)的索引文件和对应的hash。内部所列文件的位置是相对该文件的。比如上面的的source.list内容,为了获取main组件,apt会扫描
http://mirrors.163.com/ubuntu/dists/precise/Release文件得到main/binary-amd64/Packages.gz组合成最终的地址http://mirrors.163.com/ubuntu/dists/precise/main/binary-amd64/Packages.gz。这里面就是precise发布版里main组件的所有软件索引。
以binary-$arch命名的文件夹里是二进制文件的目录,源文件的目录在source文件夹。
Package列出的文件是相对于$ARCHIVE_ROOT的。
Packages 和 Sources目录是是控制文件,包括索引、翻译和差异等。
.deb文件是debian的包文件
.dsc是debian的源码描述文件
.tar是打包的文件
.gz和.bz2是压缩的文件
Release 文件的内容
上面已经说到,release文件就是索引文件。除了具体文件的hash和位置之外,一般还有其他的信息。
下面是release为文件的截图,注意:这只截取了开头的部分,完整的内容请参看实际的文件。
可选项,这些提供了一些repo的基本信息
Description: 描述
Origin:repo的来源
Label:标签说明
Suite: 套件,就是前面说的distribution
Codename: 发布的代号
决定repo布局的选项
Components: 对应前面的组件
Architectures:系统的架构
功能性的选项
Date:release文件的创建日期
Valid-Util:保质期
MD5Sum, SHA1, SHA256: 指使文件的位置和认证索引文件的真伪,包括:
checksum
文件大小
文件名
其中四个选项是server端必须的:
SHA256
Suite and/or Codename
Architectures
Components
Package文件的内容
文件dists/$DIST/$COMP/binary-$ARCH/Packages是二进制包的索引。这个文件分成很多段,每一段是一个具体文件包的说明,上图是一个包的完整实例。其中包括的选项有:
Filename:文件名,相对于$ARCHIVE_ROOT的路径(必须)
Size: 文件大小,byte为单位(必须)
MD5Sum, SHA1,SHA256:加密hash,验证wfjm(推荐)
Description-md5(可选)
Sources文件的内容
文件$DIST/$COMP/source/Sources被称为源码文件索引。它们和Packages文件相似,分为很多段,每一段描述一个源码文件包。
几个重要的选项有:
Directory: 文件包所在的目录
Package: 文件名
version: 版本号
Priority: 优先级,包括source、optional等选项
Files: 包括的文件
Checksums-Sha1(256): 校验和
apt-get 的流程
apt的工作流程:
apt程序解析source.list,根据后面的uri和发行版得到release的文件的位置
dns解析url的ip,请求release文件,解析组件的release文件和package文件,根据package文件里的内容找到所要装的文件包,并验证所有文件的合法性。
如果文件包有依赖(depends),继续使用上述的方法定位到依赖的安装包。安装所有依赖后,再安装该软件包。
如果文件包没有依赖,直接安装。
定制自己的source.list文件
1.找到repo的根目录($ARCHIVE_ROOT),就是包含dists和pool目录的那个目录,记为
2.打开dists目录,记下其中的子目录名称,找到自己要使用的版本名
3.打开pool目录,找到里面的组件名称
4.编写自己的source.list,格式为deb url codename component。
5.更新一下:sudo apt-get update。
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.