大部分内容来自man手册 TODO: 了解这类包管理工具的架构;如果可能的话,看看源码
apt
Advanced Package Tool, apt
apt换源
Ubuntu版本为18.04 LTS,更详细内容可查看清华大学开源软件镜像站
打开/etc/apt/sources.list
,内容替换为(因为是虚拟机就懒得备份了)
1
2
3
4
5
6
7
8
9
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
Commands
-
update
从/etc/apt/sources.list
(其实还包括/etc/apt/source.list.d/
)中指定源获取package信息。 -
upgrade
更新所有有新版本的package。通常使用upgrade
前需要先运行update
来保证软件包的信息是最新的。 -
install pkg(s)
安装一个或多个包,包名前使用减号(-)等同于remove,可以使用等号(=)指定版本号 -
search
按照给定的正则表达式在软件包列表中搜索。或者使用apt-file
搜索包含指定文件的软件包。 -
edit-sources
编辑sources.list
。(跟自己进入目录编辑/etc/apt/sources.list
相比少敲几个字符罢了;可以用sudo select-editor
选择/切换编辑器) -
#apt-get command#
-
source
source-pkg
获取package源码,将源码下载到当前目录Source packages are tracked separately from binary packages via deb-src lines in the sources.list(5) file. This means that you will need to add such a line for each repository you want to get sources from; otherwise you will probably get either the wrong (too old/too new) source versions or none at all.
所以这就是
sources.list
中deb-src行的作用。
-
Options
-y, --yes, --assume-yes
apt update后仍不安装最新软件包?(TODO)
科大源,golang安装1.10.x?
aptitude
用法大致与apt相似。至于区别,根据这里的解释,
Aptitude is a high-level package manager while APT is lower-level package manager which can be used by other higher-level package managers
Aptitude有UI界面,我试了一下感觉还不如命令行呢。似乎说aptitude在某些依赖的管理上比apt做得更好,目前用的不多。知道这么个东西就行了。
yum
To Be Comtinued…
腾讯云学生优惠的轻量级应用服务器不提供Ubuntu,只好选了CentOS 7.6。之前搭梯子的服务器也是CentOS,不过很久没出问题就一直没碰,现在要用了还得一点点重新捡起来。
Yellow dog Updater, Modified(Yum),是CentOS的默认包管理工具。~~ 好像以前听过全称,但是再看一次还是觉得这名字奇怪得离谱/doge。~~
yum的配置文件路径是/etc/yum.conf
。(虽然并不知道什么时候会有修改配置文件的需求)
这里主要还是记录yum的命令,和apt做个对比加深记忆,附上yum的wiki手册,下边摘录的常见命令也基本来自这份手册。(也有可能是跟apt弄混了逐渐走向混沌)
yum search
列出某个包的不同版本,可以列出多个关键词,会按照匹配程度先后列出检索到的包。
yum provides/whatprovides
列出提供某个命令的包,比如yum provides go
可以列出golang,可以配合yum search来查找想要安装package的名字,免去从ubuntu/debian转来记不住包名的烦恼;不过有时候可能会得到版本比较旧的包,还得配合搜索引擎使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[ ~]$ yum provides go
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
golang-1.15.2-1.el7.x86_64 : The Go Programming Language
Repo : epel
Matched from:
Provides : go = 1.15.2-1.el7
golang-1.15.2-1.el7.x86_64 : The Go Programming Language
Repo : @epel
Matched from:
Provides : go = 1.15.2-1.el7
yum update/upgrade
yum的update
命令跟apt的不同,根据man手册,如果update
不指定包名,则会更新所有可以升级的包;如果指定包名,则更新特定的包。update-to
命令则需要指定特定的版本来进行更新。upgrade
加上--obsolete
参数则等效于update
命令。如果想要列出可升级的包,可以使用check-update
yum check-update
列出可升级的包名