标签:rpm、yum
rpm和yum是centos上软件安装比较常用的工具
RPM包管理的用途
1、可以安装、删除、升级和管理软件;当然也支持在线安装和升级软件;
2、通过RPM包管理能知道软件包包含哪些文件,也能知道系统中的某个文件属于哪个软件包;
3、可以在查询系统中的软件包是否安装以及其版本;
4、作为开发者可以把自己的程序打包为RPM 包发布;
5、软件包签名GPG和MD5的导入、验证和签名发布
6、依赖性的检查,查看是否有软件包由于不兼容而扰乱了系统;
RPM的使用权限:
RPM软件的安装、删除、更新只有root权限才能使用;对于查询功能任何用户都可以操作;如果普通用户拥有安装目录的权限,也可以进行安装
如果RPM系统出了问题,不能安装和查询,需要初始化rpm数据库
[root@class-1 ~]# rpm --initdb [root@class-1 ~]# rpm --rebuilddb
RPM查询功能
rpm -q [select-options] [query-options]
select-options:
-a 所有包
-f 查询指定的文件由哪个程序生成
-g 查询包组
-p /path/path/file 针对没有安装的程序包文件做查询操作
--whatprovides CAPABILITY 查询指定的CAPABILITY提供由哪些包所提供
--whatrequires CAPABILITY 查询指定的CAPABILITY被哪些包所依赖
[root@class-1 ~]# rpm -qf /bin/cat #文件 coreutils-8.4-37.el6.x86_64
query-options 软件包的名称
-c 查询程序的配置文件
-d 查询程序的文档
-i 程序的制作等相关信息
-l 安装后生成的文件
--scripts 程序自带的脚本片段
-R 查询指定的程序包所有依赖的CAPABILITY
--provides 列出指定程序包所提供的CAPABILITY
--changelog 查询rpm的changelog
[root@class-1 ~]# rpm -qi httpd Name : httpd Relocations: (not relocatable) Version : 2.2.15 Vendor: CentOS Release : 39.el6.centos Build Date: Thu 16 Oct 2014 10:49:26 PM CST Install Date: Thu 27 Aug 2015 10:16:58 AM CST Build Host: c6b9.bsys.dev.centos.org Group : System Environment/Daemons Source RPM: httpd-2.2.15-39.el6.centos.src.rpm Size : 3085394 License: ASL 2.0 Signature : RSA/SHA1, Sat 18 Oct 2014 04:02:19 AM CST, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://httpd.apache.org/ Summary : Apache HTTP Server Description : The Apache HTTP Server is a powerful, efficient, and extensible web server.
需要特殊指出的是,在-q后面加上参数-p是对没有安装的软件包查询相关信息
rpm -qp query-options 软件包的名称
所使用的参数跟rpm -q相似。
RPM安装功能
rpm -ivh rpmpacks ...
-i 安装
-h 以“#”显示程序包管理安装进度
-v 显示详细信息
[root@class-1 Packages]# rpm -ivh zsh-4.3.10-7.el6.x86_64.rpm warning: zsh-4.3.10-7.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:zsh ########################################### [100%]
相关参数
--test,测试安装,但不真正执行安装
--nodeps 忽略依赖关系
--replacepkgs 重新安装
--nosignature 不检查来源合法性
--nodigest 不检查包完整性
--noscipts 不执行包脚本片段
RPM升级、卸载
rpm -Uvh rpmpacks 安装有旧版本程序包,则升级,不存在旧的程序包,则安装
rpm -Fvh rpmpacks 安装有旧版本程序包,则升级,不存在旧的程序包,则不执行升级
--oldpackage 降级
--force 强行升级
rpm -e 软件包的名称
--test 只执行删除的测试
--noscripts 不运行预安装和后安装脚本程序
--nodeps 不检查依赖性
注意 1.不要对内核做升级操作,Linux支持多内核版本并存,因此,直接安装新版本的内核。
2.如果源程序包的配置文件安装后曾被修改,升级时,新版本的提供的同一个配置文件并不会直接覆盖老版本的配置文件,而把新版本的文件重新后保留。
YUM管理
创建本地yum源
[root@class-1 media]# mount /dev/cdrom /media/cdrom/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@class-1 media]# cd cdrom/ [root@class-1 cdrom]# ls CentOS_BuildTag EULA images Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL [root@class-1 cdrom]# vi /etc/yum.repos.d/CentOS-Base.repo #在最后加入下面的一段 [localhost] name=local yum source baseurl=file:///media/cdrom/ gpgcheck=0 gpgkey= [root@class-1 cdrom]# yum repolist #缓存redata到本地 Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors * base: mirrors.neusoft.edu.cn * extras: mirrors.btte.net * updates: mirror.bit.edu.cn base | 3.7 kB 00:00 extras | 3.4 kB 00:00 localhost | 4.0 kB 00:00 ... localhost/primary_db | 4.5 MB 00:00 ... updates | 3.4 kB 00:00 repo id repo name status base CentOS-6 - Base 6,575 extras CentOS-6 - Extras 35 localhost local yum source 6,518 updates CentOS-6 - Updates 263 repolist: 13,391 [root@class-1 cdrom]# yum list ... yum-plugin-rpm-warm-cache.noarch 1.1.30-30.el6 localhost yum-plugin-show-leaves.noarch 1.1.30-30.el6 localhost yum-plugin-tmprepo.noarch 1.1.30-30.el6 localhost yum-plugin-tsflags.noarch 1.1.30-30.el6 localhost yum-plugin-upgrade-helper.noarch 1.1.30-30.el6 localhost yum-plugin-verify.noarch 1.1.30-30.el6 localhost yum-plugin-versionlock.noarch 1.1.30-30.el6 localhost yum-presto.noarch 0.6.2-1.el6 localhost yum-updateonboot.noarch 1.1.30-30.el6 localhost zlib.i686 1.2.3-29.el6 localhost zlib-devel.i686 1.2.3-29.el6 localhost zlib-devel.x86_64 1.2.3-29.el6 localhost zlib-static.x86_64 1.2.3-29.el6 localhost [root@class-1 cdrom]# yum install -y createrepo Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Reinstall Process Loading mirror speeds from cached hostfile * extras: mirrors.btte.net * updates: mirror.bit.edu.cn Resolving Dependencies --> Running transaction check ---> Package createrepo.noarch 0:0.9.9-22.el6 will be reinstalled --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================================================== Package Arch Version Repository Size ====================================================================================================================================================== Reinstalling: createrepo noarch 0.9.9-22.el6 localhost 96 k Transaction Summary ====================================================================================================================================================== Reinstall 1 Package(s) Total download size: 96 k Installed size: 291 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : createrepo-0.9.9-22.el6.noarch 1/1 Verifying : createrepo-0.9.9-22.el6.noarch 1/1 Installed: createrepo.noarch 0:0.9.9-22.el6 Complete! ###小试了下牛刀,可以安装。本地yum源已经安装OK
创建本地yum仓库
1、先安装createrepo #用iso镜像安装createrepo或者下载rpm包安装
2、对含有软件包的文件做yum仓库的repo
3、使用yum仓库时,先repolist,把redata缓存到本地
4、最后才使用yum list或install 软件
[root@class-1 ~]# ls /data/ #data目录有一个zsh的安装包 zsh-4.3.10-7.el6.x86_64.rpm [root@class-1 /]# createrepo /data/ #创建repo [root@class-1 ~]# ls /data/ repodata zsh-4.3.10-7.el6.x86_64.rpm #已创建repodata文件 [root@class-1 ~]# vi /etc/yum.repos.d/CentOS-Base.repo ###添加下面配置### [data] name=date file packages baseurl=file:///data/ gpgcheck=0 其他的各项配置全部设置成enabled=0 [root@class-1 ~]# yum list xz-libs.x86_64 4.999.9-0.5.beta.20091007git.el6 @anaconda-CentOS-201410241409.x86_64/6.6 xz-lzma-compat.x86_64 4.999.9-0.5.beta.20091007git.el6 @anaconda-CentOS-201410241409.x86_64/6.6 yelp.x86_64 2.28.1-17.el6_3 @anaconda-CentOS-201410241409.x86_64/6.6 yum.noarch 3.2.29-60.el6.centos @anaconda-CentOS-201410241409.x86_64/6.6 yum-metadata-parser.x86_64 1.1.2-16.el6 @anaconda-CentOS-201410241409.x86_64/6.6 yum-plugin-fastestmirror.noarch 1.1.30-30.el6 @anaconda-CentOS-201410241409.x86_64/6.6 yum-plugin-security.noarch 1.1.30-30.el6 @anaconda-CentOS-201410241409.x86_64/6.6 yum-utils.noarch 1.1.30-30.el6 @anaconda-CentOS-201410241409.x86_64/6.6 zd1211-firmware.noarch 1.4-4.el6 @anaconda-CentOS-201410241409.x86_64/6.6 zenity.x86_64 2.28.0-1.el6 @anaconda-CentOS-201410241409.x86_64/6.6 zip.x86_64 3.0-1.el6 @anaconda-CentOS-201410241409.x86_64/6.6 zlib.x86_64 1.2.3-29.el6 @anaconda-CentOS-201410241409.x86_64/6.6 Available Packages zsh.x86_64 4.3.10-7.el6 data 只能得到系统安装的,和data下的安装包 zsh
说说yum命令的用法
yum [options] [command] [package ...]
command is one of:
* install package1 [package2] [...]
* update [package1] [package2] [...]
* update-to [package1] [package2] [...]
* check-update
* upgrade [package1] [package2] [...]
* upgrade-to [package1] [package2] [...]
* distribution-synchronization [package1] [package2] [...]
* remove | erase package1 [package2] [...]
* list [...]
* info [...]
* provides | whatprovides feature1 [feature2] [...]
* clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
* makecache
* groupinstall group1 [group2] [...]
* groupupdate group1 [group2] [...]
* grouplist [hidden] [groupwildcard] [...]
* groupremove group1 [group2] [...]
* groupinfo group1 [...]
* search string1 [string2] [...]
* shell [filename]
* resolvedep dep1 [dep2] [...]
* localinstall rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use install)
* localupdate rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use update)
* reinstall package1 [package2] [...]
* downgrade package1 [package2] [...]
* deplist package1 [package2] [...]
* repolist [all|enabled|disabled]
* version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ]
* history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
* load-transaction [txfile]
* check
* help [command]
显示仓库列表
yum repolist [all|enabled|disabled]
显示程序
yum list [all | glob_exp1] [glob_exp2] [...]
yum list {available|installed|updates} [glob_exp1] [...]
安装程序包
yum install package1 [package2] [...]
yum reinstall package1 [package2] [...] (重新安装)
升级程序包
yum update [package1] [package2] [...]
yum downgrade package1 [package2] [...] (降级)
检查可用升级
yum check-update
卸载程序包
yum remove | erase package1 [package2] [...]
查看程序包information
yum info [...]
查看指定的特性(可以是某文件)是由哪个程序包所提供
yum provides | whatprovides feature1 [feature2] [...]
清理本地缓存
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
构建缓存
makecache
查看指定包所依赖的capabilities
yum deplist package1 [package2] [...]
查看yum事务历史
yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
包组管理的相关命令
* groupinstall group1 [group2] [...]
* groupupdate group1 [group2] [...]
* grouplist [hidden] [groupwildcard] [...]
* groupremove group1 [group2] [...]
* groupinfo group1 [...]
其他选项
--nogpgcheck:禁止进行gpg check;
-y: 自动回答为“yes”;
-q:静默模式;
--disablerepo=repoidglob:临时禁用此处指定的repo;
--enablerepo=repoidglob:临时启用此处指定的repo;
--noplugins:禁用所有插件;
标签:rpm、yum
原文地址:http://iznowow.blog.51cto.com/6232028/1689874