YUM 是 RHEL 系列用來安裝、移除與搜尋套件的工具,但很多人只把它當成「比較方便的 rpm」。實際上它最關鍵的能力是自動處理依賴:用 yum 安裝 httpd 時,它會把 apr、apr-util、httpd-tools 等需要的套件一併處理掉;若改用 rpm 手動安裝,你得自己把依賴 tree 全部找出來、依序裝完,非常折磨人。
YUM 的套件資訊來自遠端儲存庫(repository),通常由發行版或雲端平台提供。儲存庫是針對特定平台與版本所整理的一批 RPM 集合,例如 32 位元、64 位元、RHEL 5、RHEL 6 各自獨立;你也可以自建本機儲存庫並讓 yum 指向它。以下範例在 Amazon EC2 的 RHEL 6.4 上以 httpd 為例說明。
# yum search httpd Loaded plugins: amazon-id, rhui-lb, security ==================== N/S Matched: httpd ========== httpd.x86_64 : Apache HTTP Server httpd-devel.i686 : Development interfaces for the Apache HTTP server httpd-devel.x86_64 : Development interfaces for the Apache HTTP server httpd-manual.noarch : Documentation for the Apache HTTP server httpd-tools.x86_64 : Tools for use with the Apache HTTP Server mod_dav_svn.x86_64 : Apache httpd module for Subversion server mod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support
若想知道某個套件由哪個儲存庫提供、實際版本為何,改用 yum provides:
# yum provides httpd Loaded plugins: amazon-id, rhui-lb, security httpd-2.2.15-26.el6.x86_64 : Apache HTTP Server Repo : rhui-REGION-rhel-server-releases Matched from:
先列出所有可用群組:
# yum grouplist
輸出會同時顯示已安裝與可安裝的群組。要一次裝好某個群組(例如 PHP 支援),用 groupinstall:
# yum groupinstall "PHP Support" Loaded plugins: amazon-id, downloadonly, rhui-lb, security Setting up Group Process Warning: Group Support does not exist. Resolving Dependencies -> Running transaction check --> Package php.x86_64 0:5.3.3-23.el6_4 will be installed -> Processing Dependency: php-common(x86-64) = 5.3.3-23.el6_4 for package: php-5.3.3-23.el6_4.x86_64 -> Processing Dependency: php-cli(x86-64) = 5.3.3-23.el6_4 for package: php-5.3.3-23.el6_4.x86_64 --> Package php-gd.x86_64 0:5.3.3-23.el6_4 will be installed -> Processing Dependency: libXpm.so.4()(64bit) for package: php-gd-5.3.3-23.el6_4.x86_64 --> Package php-pdo.x86_64 0:5.3.3-23.el6_4 will be installed --> Package php-pear.noarch 1:1.9.4-4.el6 will be installed --> Package php-xml.x86_64 0:5.3.3-23.el6_4 will be installed --> Running transaction check --> Package libXpm.x86_64 0:3.5.10-2.el6 will be installed --> Package php-cli.x86_64 0:5.3.3-23.el6_4 will be installed --> Package php-common.x86_64 0:5.3.3-23.el6_4 will be installed -> Finished Dependency Resolution Dependencies Resolved ================================================================== Package Arch Version Repository Size ================================================================== Installing: php x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 1.1 M php-gd x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 106 k php-pdo x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 75 k php-pear noarch 1:1.9.4-4.el6 rhui-REGION-rhel-server-releases 393 k php-xml x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 103 k Installing for dependencies: libXpm x86_64 3.5.10-2.el6 rhui-REGION-rhel-server-releases 51 k php-cli x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 2.2 M php-common x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 524 k Transaction Summary ================================================================== Install 8 Package(s) Total download size: 4.5 M Installed size: 16 M Is this ok [y/N]: y Downloading Packages: (1/8): libXpm-3.5.10-2.el6.x86_64.rpm | 51 kB 00:00 (2/8): php-5.3.3-23.el6_4.x86_64.rpm | 1.1 MB 00:00 (3/8): php-cli-5.3.3-23.el6_4.x86_64.rpm| 2.2 MB 00:00 (4/8): php-common-5.3.3-23.el6_4.x86_64 | 524 kB 00:00 (5/8): php-gd-5.3.3-23.el6_4.x86_64.rpm | 106 kB 00:00 (6/8): php-pdo-5.3.3-23.el6_4.x86_64.rpm| 75 kB 00:00 (7/8): php-pear-1.9.4-4.el6.noarch.rpm | 393 kB 00:00 (8/8): php-xml-5.3.3-23.el6_4.x86_64.rpm| 103 kB 00:00 ----------------------------------------------- Total 2.9 MB/s | 4.5 MB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : php-common-5.3.3-23.el6_4.x86_64 1/8 Installing : php-cli-5.3.3-23.el6_4.x86_64 2/8 Installing : libXpm-3.5.10-2.el6.x86_64 3/8 Installing : php-gd-5.3.3-23.el6_4.x86_64 4/8 Installing : 1:php-pear-1.9.4-4.el6.noarch 5/8 Installing : php-5.3.3-23.el6_4.x86_64 6/8 Installing : php-xml-5.3.3-23.el6_4.x86_64 7/8 Installing : php-pdo-5.3.3-23.el6_4.x86_64 8/8 Verifying : 1:php-pear-1.9.4-4.el6.noarch 1/8 Verifying : php-xml-5.3.3-23.el6_4.x86_64 2/8 Verifying : php-common-5.3.3-23.el6_4.x86_64 3/8 Verifying : libXpm-3.5.10-2.el6.x86_64 4/8 Verifying : php-cli-5.3.3-23.el6_4.x86_64 5/8 Verifying : php-5.3.3-23.el6_4.x86_64 6/8 Verifying : php-pdo-5.3.3-23.el6_4.x86_64 7/8 Verifying : php-gd-5.3.3-23.el6_4.x86_64 8/8 Installed: php.x86_64 0:5.3.3-23.el6_4 php-gd.x86_64 0:5.3.3-23.el6_4 php-pdo.x86_64 0:5.3.3-23.el6_4 php-pear.noarch 1:1.9.4-4.el6 php-xml.x86_64 0:5.3.3-23.el6_4 Dependency Installed: libXpm.x86_64 0:3.5.10-2.el6 php-cli.x86_64 0:5.3.3-23.el6_4 php-common.x86_64 0:5.3.3-23.el6_4 Complete!
# yum install httpd Loaded plugins: amazon-id, rhui-lb, security Setting up Install Process Resolving Dependencies -> Running transaction check --> Package httpd.x86_64 0:2.2.15-29.el6_4 will be installed -> Processing Dependency: httpd-tools = 2.2.15-29.el6_4 for package: httpd-2.2.15-29.el6_4.x86_64 -> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-29.el6_4.x86_64 -> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-29.el6_4.x86_64 -> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-29.el6_4.x86_64 -> Running transaction check --> Package apr.x86_64 0:1.3.9-5.el6_2 will be installed --> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed --> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed --> Package httpd-tools.x86_64 0:2.2.15-29.el6_4 will be installed -> Finished Dependency Resolution Dependencies Resolved ================================================================== Package Arch Version Repository Size ================================================================== Installing: httpd x86_64 2.2.15-29.el6_4 rhui-REGION-rhel-server-releases 821 k Installing for dependencies: apr x86_64 1.3.9-5.el6_2 rhui-REGION-rhel-server-releases 123 k apr-util x86_64 1.3.9-3.el6_0.1 rhui-REGION-rhel-server-releases 87 k apr-util-ldap x86_64 1.3.9-3.el6_0.1 rhui-REGION-rhel-server-releases 15 k httpd-tools x86_64 2.2.15-29.el6_4 rhui-REGION-rhel-server-releases 73 k Transaction Summary ================================================================== Install 5 Package(s) Total download size: 1.1 M Installed size: 3.6 M Is this ok [y/N]: y
注意安裝列表中多出的四個套件,這就是 yum 的依賴解析在替你做事。若不想被 [y/N] 中斷(例如寫在腳本裡),加上 -y:yum install -y httpd。
# yum update httpd Loaded plugins: amazon-id, rhui-lb, security Setting up Update Process No Packages marked for Update
這則訊息代表目前安裝的 httpd 已經是儲存庫中的最新版本,沒有需要更新的內容。
把 search、provides、grouplist、groupinstall、install、update 這幾個指令記熟,日常在 RHEL 上管理套件基本就夠用了。