software, program, cd

RPM 軟體套件管理工具

RPM 使用方式

RPM 在 RHEL 紅帽系列家族 (Fedora、CentOS、Rocky Linux、 Oracle Linux等)都已經內建好了,可以直接使用,最常使用來查看某個套件是不是已經安裝了、套件相關內容有哪些及安裝

一、 RPM 查詢

rpm  -q  [query-options]

1. 查詢已經安裝的套件

[root@serverb ~]# rpm -qa httpd
httpd-2.4.37-43.module+el8.5.0+727+743c5577.1.x86_64

2. 查詢套件清單

[root@serverb ~]# rpm -ql  httpd
/etc/httpd/conf 
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf 
...

3. 查詢套件資訊

[root@serverb ~]# rpm -qi httpd
Name        : httpd
Version     : 2.4.37
Release     : 43.module+el8.5.0+727+743c5577.1
Architecture: x86_64
Install Date: Mon 28 Feb 2022 07:02:18 PM CST
Group       : System Environment/Daemons
Size        : 4494315
License     : ASL 2.0
Signature   : RSA/SHA256, Wed 26 Jan 2022 12:34:48 AM CST, Key ID 15af5dac6d745a60
Source RPM  : httpd-2.4.37-43.module+el8.5.0+727+743c5577.1.src.rpm
Build Date  : Wed 26 Jan 2022 12:27:31 AM CST
Build Host  : ord1-prod-x86build003.svc.aws.rockylinux.org
Relocations : (not relocatable)
Packager    : infrastructure@rockylinux.org
Vendor      : Rocky
URL         : https://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

4. 查詢套件文件

[root@serverb ~]# rpm -qd httpd
/usr/share/doc/httpd/ABOUT_APACHE
/usr/share/doc/httpd/CHANGES
/usr/share/doc/httpd/LICENSE
...

5. 查詢套件設定檔

[root@serverb ~]# rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
...

6. 查詢套件安裝腳本內容

[root@serverb ~]# rpm -q --scripts httpd
postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then 
        # Initial installation 
        systemctl --no-reload preset httpd.service htcacheclean.service httpd.socket &>/dev/null || : 
fi
preuninstall scriptlet (using /bin/sh):

...

上述均只能查詢已經安裝在系統內,如果要查詢下載的 package ,需要帶 -p 參數並指定 package 位置

7. 查詢機器內某檔案是哪個套件安裝的

[root@serverb ~]# rpm -qf /var/www/html/
httpd-filesystem-2.4.37-43.module+el8.5.0+727+743c5577.1.noarch

二、 RPM 安裝

rpm  -i  [install-options]
  • -h 及 -v 顯示更多詳細安裝訊息及進度
[root@serverb ~]# rpm -ihv zsh-5.5.1-6.el8_1.2.x86_64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.5.1-6.el8_1.2              ################################# [100%]

三、 RPM 移除

rpm  -e 
  • -v 顯示更多詳細移除訊息
[root@serverb ~]# rpm -ev zsh 
Preparing packages...
zsh-5.5.1-6.el8_1.2.x86_64

RPM 優缺點

從上述操作可以看到 RPM 無論是管理套件或是安裝都是好用且方便的好工具,但是一旦遇到該套件安裝是需要額外相依性套件時,就會安裝失敗。需要手動一步一步把相依性套件補齊,結果如下:

[root@serverb ~]# rpm -ivh php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64.rpm 
error: Failed dependencies:
	httpd-filesystem is needed by php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64
	httpd-mmn = 20120211x8664 is needed by php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64
	php-cli(x86-64) = 7.2.24-1.module+el8.4.0+413+c9202dda is needed by php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64
	php-common(x86-64) = 7.2.24-1.module+el8.4.0+413+c9202dda is needed by php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64

後來就有好心人針對 RPM 這個管理套件工具開發更進階的 YUM (Yellow dog Updater, Modified) ,可以從指定的伺服器自動下載套件及處理相關相依性套件一併安裝。

  • 在 RHEL 8 系列版本之後已經改成 DNF 優化版的 YUM 套件管理工具 ( 還是可以使用 yum 指令,透過軟連結指向 DNF)

小測驗

測驗一 :

查看 firewalld 套件的 Summary 及 URL

測驗二 :

wget 下載 http://mirror01.idc.hinet.net/rockylinux/8.5/BaseOS/x86_64/os/Packages/z/zsh-5.5.1-6.el8_1.2.x86_64.rpm 套件後,使用 RPM 套件管理工具安裝

測驗三 :

上述題目安裝的 zsh 套件,有哪些 config 相關設定檔案?

- [ ] 測驗一檢視
- [ ] 測驗二檢視
- [ ] 測驗三檢視 

測驗解答

  1. 測驗一解答 :

查看 firewalld 套件的 Summary 及 URL

[root@serverb ~]# rpm -qi firewalld
...
Summary     : A firewall daemon with D-Bus interface providing a dynamic firewall
URL         : http://www.firewalld.org
...
  1. 測驗二解答 :

wget 下載 http://mirror01.idc.hinet.net/rockylinux/8.5/BaseOS/x86_64/os/Packages/z/zsh-5.5.1-6.el8_1.2.x86_64.rpm 套件後,使用 RPM 套件管理工具安裝

[root@serverb ~]# rpm -ivh zsh-5.5.1-6.el8_1.2.x86_64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.5.1-6.el8_1.2              ################################# [100%]
  1. 測驗三解答 :

上述題目安裝的 zsh 套件,有哪些 config 相關設定檔案?

[root@serverb ~]# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc

Similar Posts