歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Red hat Linux

在紅帽Linux中使用YUM包管理器

YUM是RHEL系統中提供的一個安裝,卸載和搜索軟件包的工具。它能做的不僅僅是安裝、卸載軟件包,它能做的還有更多,下面我們將在本文中為你展示。

YUM可以自動安裝軟件包的依賴包,例如當你使用yum安裝httpd時,它還會自動安裝https apache server以及它依賴的軟件包。通過rpm軟件包安裝時就沒有這麼方便咯(譯注:就是不會自動處理軟件包依賴問題咯!),你必須下載所有它依賴的軟件包,然後依序安裝它們。

yum工具從遠端服務器上的軟件倉庫(通常由OS提供商提供)獲取軟件包的信息。一個軟件倉庫是能在特定架構上運行的一系列rpm軟件包的集合。例如,對於32位和64位系統各有一個軟件倉庫,還有針對RHEL5以及RHEL6的軟件倉庫。你也可以建立一個本地倉庫,配置你的yum讓其從你的本地倉庫裡搜索安裝軟件包。在接下來的例子中,我將向你展示除了安裝和卸載軟件,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 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 provides httpd在軟件倉庫裡搜索含有httpd的軟件包。

提供所有軟件組列表

# yum grouplist

以上命令將為你顯示已經安裝的以及可用的軟件組。你可以使用軟件組安裝選項來安裝其中一個軟件組。例如,我們將安裝一個PHP Support的軟件組。這個軟件組內包含需要的PHP軟件包。

# 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.rpm | 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安裝軟件包

可以使用yum install命令安裝軟件包,如下所示:

#  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

如你所見,在安裝httpd時yum安裝了額外的軟件包。這稱為yum完成的依賴包解析。

假如你不想讓yum彈出[y/N]選項,可以使用yum install -y httpd

使用yum update 命令更新一個已存在的軟件包

# yum update httpd
Loaded plugins: amazon-id, rhui-lb, security
Setting up Update Process
No Packages marked for Update

這意味著你系統中安裝的httpd軟件包已經是yum軟件倉庫裡的最新版本的了。

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2013-11/92971p2.htm

推薦閱讀:

配置EPEL YUM源 http://www.linuxidc.com/Linux/2012-10/71850.htm

RedHat 本地yum源配置 http://www.linuxidc.com/Linux/2012-11/75127.htm

RedHat Linux 本地yum源的配置 http://www.linuxidc.com/Linux/2013-08/88217.htm

RedHat 6.2 Linux修改yum源免費使用CentOS源 http://www.linuxidc.com/Linux/2013-07/87383.htm

更多RedHat相關信息見RedHat 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=10

Copyright © Linux教程網 All Rights Reserved