Linux-rpm包管理

Linux-rpm包管理

获取程序包的途径

软件包管理器的核心功能

  • 制作软件包
  • 安装软件
  • 卸载软件
  • 升级软件
  • 查询软件
  • 校验软件

软件包管理工具

  • 分类:
    • 前端工具,常用的前端工具有以下这些:
      • yum
      • apt-get
      • zypper (suse上的rpm前端管理工具)
      • dnf(Fedora 22+ rpm前端管理工具)
    • 后端工具,常用的后端工具有以下这些:
      • rpm
      • dpt
  • 注意:
    • 前端工具是依赖于后端工具的
    • 前端工具是为了自动解决后端工具的依赖关系而存在的

软件安装方式

  • 通过前端工具安装
  • 通过后端工具安装
  • 编译安装

rpm包命名规范

img

  • 包的组成
    • 主包:bind-9.7.1-1.el5.i586.rpm
    • 子包:bind-libs-9.7.1-1.el5.i586.rpm bind-utils-9.7.1-1.el5.i586.rpm
  • 包名格式
    • name-version-release-arch.rpm
      • bind-major.minor.release-release.arch.rpm
  • 包名格式说明
    • major(主版本号):重大改进
    • minor(次版本号):某个子功能发生重大变化
    • release(发行号):修正了部分bug,调整了一点功能
  • 常见的arch
    • x86:i386,i486,i586,i686
    • x86_64:x64,x86_64,amd64
    • 跟平台无关:noarch

rpm包管理

什么是rpm及其作用

rpm是Redhat Package Manager的简称,用于管理软件包。
rpm有一个强大的数据库/var/lib/rpm。
rpm的管理工作包括软件的安装、卸载、升级、查询、校验、重建数据库、验证软件包来源合法性等等。

RPM包安装

// 常用选项:
	-i: 安装
    -v: 显示详细信息
    -h: 显示安装进度条

//安装软件包, 指定软件包绝对路径
[root@localhost ~]# rpm -ivh /mnt/AppStream/Packages/vsftpd-3.0.3-31.el8.x86_64.rpm 
warning: /mnt/AppStream/Packages/vsftpd-3.0.3-31.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.3-31.el8              ################################# [100%]
   
//忽略依赖关系
[root@localhost ~]# rpm -ivh --nodeps /mnt/AppStream/Packages/vsftpd-3.0.3-31.el8.x86_64.rpm 

RPM包升级

//-Uvh 如果装有老版本的就升级;如果没装就跟你安装
  -Fvh 如果装有老版本的就升级;如果没装就退出不安装
  --oldpackage	降级
  
//下一个旧版本的安装包
[root@localhost ~]# curl -o wget-1.14-18.el7_6.1.x86_64.rpm http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time   Current
                                 Dload  Upload   Total   Spent    Left   Speed
100  547k  100  547k    0     0  83660      0  0:00:07  0:00:07  --:--:-- 122k
[root@localhost ~]# ls
anaconda-ks.cfg  wget-1.14-18.el7_6.1.x86_64.rpm

//下载好后直接安装发现需要依赖包才能安装
[root@localhost ~]# rpm -ivh wget-1.14-18.el7_6.1.x86_64.rpm 
warning: wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
	libcrypto.so.10()(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libcrypto.so.10(libcrypto.so.10)(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libidn.so.11()(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libidn.so.11(LIBIDN_1.0)(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libssl.so.10()(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libssl.so.10(libssl.so.10)(64bit) is needed by wget-1.14-18.el7_6.1.x86_64

//直接忽略依赖关系安装
[root@localhost ~]# rpm -ivh --nodeps wget-1.14-18.el7_6.1.x86_64.rpm 
warning: wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:wget-1.14-18.el7_6.1             ################################# [100%]
[root@localhost ~]# rpm -qa|grep wget
wget-1.14-18.el7_6.1.x86_64

//-Fvh用新软件包升级
[root@localhost ~]# rpm -Fvh /mnt/AppStream/Packages/wget-1.19.5-8.el8_1.1.x86_64.rpm 
warning: /mnt/AppStream/Packages/wget-1.19.5-8.el8_1.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:wget-1.19.5-8.el8_1.1            ################################# [ 50%]
Cleaning up / removing...
   2:wget-1.14-18.el7_6.1             ################################# [100%]
[root@localhost ~]# rpm -qa|grep wget
wget-1.19.5-8.el8_1.1.x86_64

//卸载软件包
[root@localhost ~]# rpm -e wget

//-Uvh没有旧软件包直接安装新软件包
[root@localhost ~]# rpm -Uvh /mnt/AppStream/Packages/wget-1.19.5-8.el8_1.1.x86_64.rpm 
warning: /mnt/AppStream/Packages/wget-1.19.5-8.el8_1.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:wget-1.19.5-8.el8_1.1            ################################# [100%]
[root@localhost ~]# rpm -qa|grep wget
wget-1.19.5-8.el8_1.1.x86_64

*升级注意事项:

  • 不要对内核做升级操作
    • Linux支持多内核版本并存,因此,可直接安装新版本内核
  • 如果原程序包的配置文件安装后曾被修改,升级时,新版本提供的同一个配置文件并不会直接覆盖老版本的配置文件,而把新版本的文件重命名(FILENAME.rpmnew)后保留

RPM包卸载

[root@localhost ~]# rpm -e wget

注意:如果其他包依赖于要卸载的包,这个被依赖的包是无法卸载的,除非强制卸载,强制卸载后依赖于这个包的其他程序将无法正常工作

RPM包查询

//-qa	查询已经安装的所有包
[root@localhost ~]# rpm -qa wget
wget-1.19.5-8.el8_1.1.x86_64

//-qi	查询软件包的相关信息
[root@localhost ~]# rpm -qi wget
Name        : wget
Version     : 1.19.5
Release     : 8.el8_1.1
Architecture: x86_64
Install Date: Sun 29 Nov 2020 10:32:42 PM CST
Group       : Applications/Internet
Size        : 3058289
License     : GPLv3+
Signature   : RSA/SHA256, Tue 26 Nov 2019 10:41:58 PM CST, Key ID 199e2f91fd431d51
Source RPM  : wget-1.19.5-8.el8_1.1.src.rpm
Build Date  : Tue 26 Nov 2019 08:28:06 PM CST
Build Host  : x86-vm-09.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor      : Red Hat, Inc.
URL         : http://www.gnu.org/software/wget/
Summary     : A utility for retrieving files using the HTTP or FTP protocols
Description :
GNU Wget is a file retrieval utility which can use either the HTTP or
FTP protocols. Wget features include the ability to work in the
background while you are logged out, recursive retrieval of
directories, file name wildcard matching, remote file timestamp
storage and comparison, use of Rest with FTP servers and Range with
HTTP servers to retrieve files over slow or unstable connections,
support for Proxy servers, and configurability.

//-ql	查询指定软件包安装后生成的文件列表
[root@localhost ~]# rpm -ql wget
/etc/wgetrc
/usr/bin/wget
/usr/lib/.build-id
/usr/lib/.build-id/18
/usr/lib/.build-id/18/333ad81a17b7899aa7e3cd6758b2f81aaeca82
......
/usr/share/locale/uk/LC_MESSAGES/wget.mo
/usr/share/locale/vi/LC_MESSAGES/wget.mo
/usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
/usr/share/locale/zh_TW/LC_MESSAGES/wget.mo
/usr/share/man/man1/wget.1.gz

//-qf	查询指定的文件是由哪个rpm包安装生成的
[root@localhost ~]# which pstree
/usr/bin/pstree
[root@localhost ~]# rpm -qf /usr/bin/pstree
psmisc-23.1-4.el8.x86_64

//-qc	查询指定包安装的配置文件
[root@localhost ~]# rpm -qc wget
/etc/wgetrc

//-qd	查询指定包安装的帮助文件
[root@localhost ~]# rpm -qd wget
/usr/share/doc/wget/AUTHORS
/usr/share/doc/wget/COPYING
/usr/share/doc/wget/MAILING-LIST
/usr/share/doc/wget/NEWS
/usr/share/doc/wget/README
/usr/share/doc/wget/sample.wgetrc
/usr/share/info/wget.info.gz
/usr/share/man/man1/wget.1.gz

//-q --whatprovides	查询指定的CAPABILITY(能力)由哪个包所提供
[root@localhost ~]# rpm -q --whatprovides /usr/bin/pstree
psmisc-23.1-4.el8.x86_64
原文地址:https://www.cnblogs.com/yuqinghao/p/14068453.html