作为较为常用的两大发行版Redhat以及Debian系,集成的PM工具可以很好的解决软件包的依赖,下面介绍下用法.

apt-get

apt的软件源配置文件在/etc/apt目录下,通常是下面这样的

1
2
deb http://security.ubuntu.com/ubuntu trusty-security main
deb-src http://security.ubuntu.com/ubuntu trusty-security main

deb表示是.deb结尾的软件包, 而另一个是可供下载的源码.

命令如下:
update - 重新获取软件包列表
upgrade - 进行更新
install - 安装新的软件包
remove - 移除软件包
autoremove - 自动移除全部不使用(不再依赖)的软件包
purge - 移除软件包和配置文件
source - 下载源码档案
build-dep - 为源码包配置编译依赖
dist-upgrade - 发行版升级, 参见 apt-get(8)
dselect-upgrade - 依照 dselect 的选择更新
clean - 清除下载的归档文件 (/var/lib/apt)
autoclean - 清除旧的的已下载的归档文件
check - 检验是否有损坏的依赖

选项:
-h 本帮助文件。
-q 输出到日志 - 无进展指示
-qq 不输出信息,错误除外
-d 仅下载 - 不安装或解压归档文件
-s 不实际安装。模拟执行命令
-y 假定对所有的询问选是,不提示
-f 尝试修正系统依赖损坏处
-m 如果归档无法定位,尝试继续
-u 同时显示更新软件包的列表
-b 获取源码包后编译
-V 显示详细的版本号
-c=? 阅读此配置文件
-o=? 设置自定的配置选项,如 -o dir::cache=/tmp

apt-get 常用实例

apt-cache search packagename 搜索包
apt-cache show packagename 获取包的相关信息,如说明、大小、版本等
apt-get install packagename 安装包
apt-get install packagename - - reinstall 重新安装包
apt-get -f install 修复安装”-f = –fix-missing”
apt-get remove packagename 删除包 不删除配置 不删除依赖
apt-get remove packagename - - purge 删除包,包括删除配置文件等
apt-get update 更新源
apt-get upgrade 更新已安装的包
apt-get dist-upgrade 升级系统
apt-get dselect-upgrade 使用 dselect 升级
apt-cache depends packagename 了解使用依赖
apt-cache rdepends packagename 是查看该包被哪些包依赖
apt-get build-dep packagename 安装相关的编译环境
apt-get source packagename 下载该包的源代码
apt-get clean 清理无用的包
apt-get autoclean 清理无用的包
apt-get check 检查是否有损坏的依赖

据说 aptitude可以更好的解决依赖问题,同时aptitude也有类GUI界面 安装apt-get install aptitude

这种一般都是在维护的源中安装的,万一下载了一个.deb软件包那怎么安装呢,就要用到dpkg了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-i:安装软件包;
-r:删除软件包;
-P:删除软件包的同时删除其配置文件;
-L:显示于软件包关联的文件;
-l:显示已安装软件包列表;
--unpack:解开软件包;
-c:显示软件包内文件列表;
--confiugre:配置软件包。
-i|--install <.deb file name> ... | -R|--recursive <directory> ...
--unpack <.deb file name> ... | -R|--recursive <directory> ...
-A|--record-avail <.deb file name> ... | -R|--recursive <directory> ...
--configure <package> ... | -a|--pending
--triggers-only <package> ... | -a|--pending
-r|--remove <package> ... | -a|--pending
-P|--purge <package> ... | -a|--pending
-V|--verify <package> ... Verify the integrity of package(s).
--get-selections [<pattern> ...] Get list of selections to stdout.
--set-selections Set package selections from stdin.
--clear-selections Deselect every non-essential package.
--update-avail <Packages-file> Replace available packages info.
--merge-avail <Packages-file> Merge with info from file.
--clear-avail Erase existing available info.
--forget-old-unavail Forget uninstalled unavailable pkgs.
-s|--status <package> ... Display package status details.
-p|--print-avail <package> ... Display available version details.
-L|--listfiles <package> ... List files `owned' by package(s).
-l|--list [<pattern> ...] List packages concisely.
-S|--search <pattern> ... Find package(s) owning file(s).
-C|--audit Check for broken package(s).
--add-architecture <arch> Add <arch> to the list of architectures.
--remove-architecture <arch> Remove <arch> from the list of architectures.
--print-architecture Print dpkg architecture.
--print-foreign-architectures Print allowed foreign architectures.
--compare-versions <a> <op> <b> Compare version numbers - see below.
--force-help Show help on forcing.
-Dh|--debug=help Show help on debugging.
-?, --help Show this help message.
--version Show the version.
Use dpkg -b|--build|-c|--contents|-e|--control|-I|--info|-f|--field|
-x|--extract|-X|--vextract|--fsys-tarfile on archives (type dpkg-deb --help).
For internal use: dpkg --assert-support-predepends | --predep-package |
--assert-working-epoch | --assert-long-filenames | --assert-multi-conrep |
--assert-multi-arch.
Options:
--admindir=<directory> Use <directory> instead of /var/lib/dpkg.
--root=<directory> Install on a different root directory.
--instdir=<directory> Change installation dir without changing admin dir.
--path-exclude=<pattern> Do not install paths which match a shell pattern.
--path-include=<pattern> Re-include a pattern after a previous exclusion.
-O|--selected-only Skip packages not selected for install/upgrade.
-E|--skip-same-version Skip packages whose same version is installed.
-G|--refuse-downgrade Skip packages with earlier version than installed.
-B|--auto-deconfigure Install even if it would break some other package.
--[no-]triggers Skip or force consequential trigger processing.
--verify-format=<format> Verify output format (supported: 'rpm').
--no-debsig Do not try to verify package signatures.
--no-act|--dry-run|--simulate
Just say what we would do - don't do it.
-D|--debug=<octal> Enable debugging (see -Dhelp or --debug=help).
--status-fd <n> Send status change updates to file descriptor <n>.
--status-logger=<command> Send status change updates to <command>'s stdin.
--log=<filename> Log status changes and actions to <filename>.
--ignore-depends=<package>,...
Ignore dependencies involving <package>.
--force-... Override problems (see --force-help).
--no-force-...|--refuse-...
Stop when problems encountered.
--abort-after <n> Abort after encountering <n> errors.
Comparison operators for --compare-versions are:
lt le eq ne ge gt (treat empty version as earlier than any version);
lt-nl le-nl ge-nl gt-nl (treat empty version as later than any version);
< << <= = >= >> > (only for compatibility with control file syntax).

yum

yum的软件源配置文件在/etc/yum.repos.d目录,二进制包一般都是后缀为.rpm的软件包.
与yum相对使用rpm命令可以安装.rpm的软件包。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1. 安装
yum install //全部安装
yum install package1 //安装指定的安装包package1
yum groupinsall group1 //安装程序组group1
2. 更新和升级
yum update //全部更新
yum update package1 //更新指定程序包package1
yum check-update //检查可更新的程序
yum upgrade package1 //升级指定程序包package1
yum groupupdate group1 //升级程序组group1
3. 查找和显示
yum info package1 //显示安装包信息package1
yum list //显示所有已经安装和可以安装的程序包
yum list package1 //显示指定程序包安装情况package1
yum groupinfo group1 //显示程序组group1信息
yum search string //根据关键字string查找安装包
yum provides dig //根据文件名查找
4. 删除程序
yum remove | erase package1 //删除程序包package1
yum groupremove group1 //删除程序组group1
yum deplist package1 //查看程序package1依赖情况
5. 缓存
yum makecache //生成缓存
yum clean packages //清除缓存目录下的软件包
yum clean headers //清除缓存目录下的 headers
yum clean oldheaders //清除缓存目录下旧的 headers
yum clean, yum clean all //清除缓存目录下的软件包

rpm命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-i, --install install package(s)
-v, --verbose provide more detailed output
-h, --hash print hash marks as package installs (good with -v)
-e, --erase erase (uninstall) package
-U, --upgrade=<packagefile>+ upgrade package(s)
--replacepkge 无论软件包是否已被安装,都强行安装软件包
--test 安装测试,并不实际安装
--nodeps 忽略软件包的依赖关系强行安装
--force 忽略软件包及文件的冲突
Query options (with -q or --query):
-a, --all query/verify all packages
-p, --package query/verify a package file
-l, --list list files in package
-d, --docfiles list all documentation files
-f, --file query/verify package(s) owning file

rpm -q samba //查询程序是否安装

rpm -ivh /media/cdrom/RedHat/RPMS/samba-3.0.10-1.4E.i386.rpm //按路径安装并显示进度
rpm -ivh –relocate /=/opt/gaim gaim-1.3.0-1.fc4.i386.rpm //指定安装目录

rpm -ivh –test gaim-1.3.0-1.fc4.i386.rpm    //用来检查依赖关系;并不是真正的安装;
rpm -Uvh –oldpackage gaim-1.3.0-1.fc4.i386.rpm //新版本降级为旧版本

rpm -qa | grep httpd      #[搜索指定rpm包是否安装]–all搜索httpd
rpm -ql httpd         #[搜索rpm包]–list所有文件安装目录

rpm -qpi Linux-1.4-6.i368.rpm #[查看rpm包]–query–package–install package信息
rpm -qpf Linux-1.4-6.i368.rpm #[查看rpm包]–file
rpm -qpR file.rpm       #[查看包]依赖关系
rpm2cpio file.rpm |cpio -div #[抽出文件]

rpm -ivh file.rpm  #[安装新的rpm]–install–verbose–hash
rpm -ivh

rpm -Uvh file.rpm #[升级一个rpm]–upgrade
rpm -e file.rpm #[删除一个rpm包]–erase

apt-get 每次都会读取这个文件,从而获取的包的信息。从Packages.gz中获取到所有包的信息。Packages.gz中包含的信息有:

包名,优先级,类型,维护者,架构,源文件(source),版本号,依赖包,冲突性信息,包大小,文件的下载路径,MD5sum,SHA1,包描述,Xul-Appid—应用程序id,Bugs信息,Origin,Supported

Packages中的一个包信息实例:

Package: abrowser
Priority: optional
Section: web
Installed-Size: 153
Maintainer: Ubuntu Mozilla Team ubuntu-mozillateam@lists.ubuntu.com
Architecture: amd64
Source: firefox
Version: 11.0+build1-0ubuntu4
Depends: firefox (>= 9.0)
Filename: pool/main/f/firefox/abrowser_11.0+build1-0ubuntu4_amd64.deb
Size: 8940
MD5sum: e8781af38a6de76126d190fc10a14bf2
SHA1: 408abd5f960d4b02bc18581df348954eb7620772
SHA256: cdfad0e4435c035b3115bdec08d79ccfc68bf9480e89df9270b3b6befa348699
Description: Safe and easy web browser from Mozilla – transitional package
Description-md5: e89058e4775caff7d26313fa8811675e
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 18m

Main - Canonical-supported free and open-source software.

Universe - Community-maintained free and open-source software.

Restricted - Proprietary drivers for devices.

Multiverse - Software restricted by copyright or legal issues.

http://blog.51yip.com/linux/1176.html
http://www.jianshu.com/p/0cf2c57bd61b
http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html