RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序”因而广受欢迎。逐渐受到其他发行版的采用。RPM套件管理方式的出现,让Linux易于安装,升级,间接提升了Linux的适用度。
rpm 执行安装包
二进制包(Binary)以及源代码包(Source)两种。二进制包可以直接安装在计算机中,而源代码包将会由RPM自动编译、安装。源代码包经常以src.rpm作为后缀名。
源代码:name-VERSION.tar.gz|bz2|xz
VERSION: major.minor.release
rpm包命名方式:
name-VERSION-release.arch.rpm
例:bash-4.2.46-19.el7.x86_64.rpm
VERSION: major.minor.release
release:release.OS
常见的arch:
x86: i386, i486, i586, i686
x86_64: x64, x86_64, amd64powerpc: ppc
跟平台无关:noarch
程序包管理器:
功能:将编译好的应用程序的各组成文件打包一个或几个程序包文件,从而方便快捷地实现程序包的安装、卸载、查询、升级和校验等管理操作
语法格式
rpm [option] [argiment]
常用组合命令
-ivh:安装显示安装进度–install–verbose–hash
-Uvh:升级软件包–Update;
-qpl:列出RPM软件包内的文件信息[Query Package list];
-qpi:列出RPM软件包的描述信息[Query Package install package(s)];
-qf:查找指定文件属于哪个RPM软件包[Query File];
-Va:校验所有的RPM软件包,查找丢失的文件[View Lost];
-e:删除包[erase]
rpm -ivh file.rpm #[安装新的rpm并用#显示进度]–install–verbose–hash
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 -q tree //#查询程序是否安装,安装了会显示软件包名。
rpm -qpi #查看rpm包–query–package–install package信息
rpm -qpi tree-1.5.3-3.el6.x86_64.rpm #查看rpm包–file
rpm -qpR file.rpm #[查看包]依赖关系
rpm2cpio file.rpm |cpio -div #[抽出文件]
rpm -Uvh file.rpm #[升级一个rpm]–upgrade
rpm -e file.rpm #[删除一个rpm包]–erase
常用参数:
Install/Upgrade/Erase options:安装,升级,卸载
-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) #升级更新安装,存在即更新,不存在即安装
{-F|–freshen} [install-options] PACKAGE_FILE… #更新升级,不存在即不安装
--replacepkge 无论软件包是否已被安装,都强行安装软件包
–test 安装测试,并不实际安装
–nodeps 忽略软件包的依赖关系强行安装
–force 忽略软件包及文件的冲突
Query options (with -q or –query):查询
-q 软件名 #查询软件是否安装
-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 # 查询根(/)上的文件是由哪个软件包生成的
-c, –configfiles #查询程序的配置文件
-R, –requires #查询软件的依赖关系
导入所需要公钥:
rpm -K|checksigrpmfile检查包的完整性和签名
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
CentOS 7发行版光盘提供:RPM-GPG-KEY-CentOS-7
rpm -qagpg-pubkey*
示例
centos7环境下
若想安装rpm包,你先得把安装光配挂载起来
[root@localhost yum.repos.d]# mkdir /media/cdrom #创建挂载目录(media和mnt常用来当挂载目录) [root@localhost yum.repos.d]# mount /dev/cdrom /media/cdrom/ #挂载 mount: /dev/sr0 is write-protected, mounting read-onl #挂载成功 [root@localhost cdrom]# ls#列出/media/cdrom下的文件 CentOS_BuildTag images repodata EFI isolinux RPM-GPG-KEY-CentOS-7 EULA LiveOS RPM-GPG-KEY-CentOS-Testing-7 GPL Packages TRANS.TBL [root@localhost cdrom]# rpm --import ./RPM-GPG-KEY-CentOS-7 #导入公钥 [root@localhost cdrom]# rpm -ivh /media/cdrom/Packages/tree-1.6.0-10.el7.x86_64.rpm #安装tree软件包等功能就可以使用了 Preparing... ################################# [100%] Updating / installing... 1:tree-1.6.0-10.el7 ################################# [100%]
yum
yum(全 称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载 RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至 全部软件包的命令,而且命令简洁而又好记。
语法
yum [options] [command] [package …]
常用选项
1 安装
yum install :全部安装
yum install package1 安装指定的安装包package1
yum groupinsall "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查找安装包
4 删除程序
yum remove | erase package1 删除程序包package1
yum groupremove group1 删除程序组group1
yum deplist package1 查看程序package1依赖情况
5 清除缓存
yum clean packages 清除缓存目录下的软件包
yum clean headers 清除缓存目录下的 headers
yum clean oldheaders 清除缓存目录下旧的 headers
yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 清除缓存目录下的软件包及旧的headers
在使用yum之前首先要安装yum库。
yum仓库的三种格式安装
ftp://
http://
file:/// (最后一个为/路径)
yum客户端配置文件:
/etc/yum.conf:为所有仓库提供公共配置
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
仓库指向的定义:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/ #必须填
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
默认为:roundrobin,意为随机挑选;
cost= 默认为1000
yum-config-manager –add-repo= http:/10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/ 自动生成仓库文件
yum-config-manager –disable “仓库名" 禁用仓库
yum-config-manager –enable “仓库名” 启用仓库
示例,篇幅太长就不多做示例了!
[root@localhost repository]# yum -y install httpd #安装httpd软件及它所依赖的包 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be installed --> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos for package: httpd-2.4.6-40.el7.centos.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.x86_64 --> Running transaction check ---> Package apr.x86_64 0:1.4.8-3.el7 will be installed ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed ---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================== Installing: httpd x86_64 2.4.6-40.el7.centos repository 2.7 M Installing for dependencies: apr x86_64 1.4.8-3.el7 repository 103 k apr-util x86_64 1.5.2-6.el7 repository 92 k httpd-tools x86_64 2.4.6-40.el7.centos repository 82 k Transaction Summary ===================================================================================================================================== Install 1 Package (+3 Dependent packages) Total download size: 3.0 M Installed size: 9.9 M Downloading packages: (1/4): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:00 (2/4): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00 (3/4): httpd-2.4.6-40.el7.centos.x86_64.rpm | 2.7 MB 00:00:00 (4/4): httpd-tools-2.4.6-40.el7.centos.x86_64.rpm | 82 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------- Total 2.7 MB/s | 3.0 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : apr-1.4.8-3.el7.x86_64 1/4 Installing : apr-util-1.5.2-6.el7.x86_64 2/4 Installing : httpd-tools-2.4.6-40.el7.centos.x86_64 3/4 Installing : httpd-2.4.6-40.el7.centos.x86_64 4/4 Verifying : httpd-2.4.6-40.el7.centos.x86_64 1/4 Verifying : apr-util-1.5.2-6.el7.x86_64 2/4 Verifying : httpd-tools-2.4.6-40.el7.centos.x86_64 3/4 Verifying : apr-1.4.8-3.el7.x86_64 4/4 Installed: httpd.x86_64 0:2.4.6-40.el7.centos Dependency Installed: apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-40.el7.centos Complete! [root@localhost repository]# yum grouplist all #查看配置的yum仓库 Loaded plugins: fastestmirror, langpacks There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile Warning: no environments/groups match: all [root@localhost repository]# yum repolist all Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile repo id repo name status base cent7 repository enabled: 8,508 repository CentOS7 repository enabled: 9,007 repolist: 17,515
原创文章,作者:ladsdm,如若转载,请注明出处:http://www.178linux.com/39621