设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

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

2013-11-20 16:49| 发布者: 红黑魂| 查看: 2529| 评论: 0|来自: Linux中国

摘要:   YUM是RHEL系统中提供的一个安装,卸载和搜索软件包的工具。它能做的不仅仅是安装、卸载软件包,它能做的还有更多,下面我们将在本文中为你展示。  YUM可以自动安装软件包的依赖包,例如当你使用yum安装httpd时 ...


  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 httpdLoaded plugins: amazon-id, rhui-lb, security==================== N/S Matched: httpd ==========httpd.x86_64 : Apache HTTP Serverhttpd-devel.i686 : Development interfaces for the Apache HTTP serverhttpd-devel.x86_64 : Development interfaces for the Apache HTTP serverhttpd-manual.noarch : Documentation for the Apache HTTP serverhttpd-tools.x86_64 : Tools for use with the Apache HTTP Servermod_dav_svn.x86_64 : Apache httpd module for Subversion servermod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support


想获得详细的输出信息,可以使用下面的命令:


# yum provides httpdLoaded plugins: amazon-id, rhui-lb, securityhttpd-2.2.15-26.el6.x86_64 : Apache HTTP ServerRepo : rhui-REGION-rhel-server-releasesMatched from:

yum provides httpd在软件仓库里搜索含有httpd的软件包。


提供所有软件组列表


# yum grouplist

以上命令将为你显示已经安装的以及可用的软件组。你可以使用软件组安装选项来安装其中一个软件组。例如,我们将安装一个PHP Support的软件组。这个软件组内包含需要的PHP软件包。


# yum groupinstall PHP SupportLoaded plugins: amazon-id, downloadonly, rhui-lb, securitySetting up Group ProcessWarning: 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 ResolutionDependencies Resolved==================================================Package Arch Version Repository Size==================================================Installing:php x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 1.1 Mphp-gd x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 106 kphp-pdo x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 75 kphp-pear noarch 1:1.9.4-4.el6 rhui-REGION-rhel-server-releases 393 kphp-xml x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 103 kInstalling for dependencies:libXpm x86_64 3.5.10-2.el6 rhui-REGION-rhel-server-releases 51 kphp-cli x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 2.2 Mphp-common x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 524 kTransaction Summary==================================================Install 8 Package(s)Total download size: 4.5 MInstalled size: 16 MIs this ok [y/N]: yDownloading 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:01Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionInstalling : php-common-5.3.3-23.el6_4.x86_64 1/8Installing : php-cli-5.3.3-23.el6_4.x86_64 2/8Installing : libXpm-3.5.10-2.el6.x86_64 3/8Installing : php-gd-5.3.3-23.el6_4.x86_64 4/8Installing : 1:php-pear-1.9.4-4.el6.noarch 5/8Installing : php-5.3.3-23.el6_4.x86_64 6/8Installing : php-xml-5.3.3-23.el6_4.x86_64 7/8Installing : php-pdo-5.3.3-23.el6_4.x86_64 8/8Verifying : 1:php-pear-1.9.4-4.el6.noarch 1/8Verifying : php-xml-5.3.3-23.el6_4.x86_64 2/8Verifying : php-common-5.3.3-23.el6_4.x86_64 3/8Verifying : libXpm-3.5.10-2.el6.x86_64 4/8Verifying : php-cli-5.3.3-23.el6_4.x86_64 5/8Verifying : php-5.3.3-23.el6_4.x86_64 6/8Verifying : php-pdo-5.3.3-23.el6_4.x86_64 7/8Verifying : php-gd-5.3.3-23.el6_4.x86_64 8/8Installed: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_4php-pear.noarch 1:1.9.4-4.el6 php-xml.x86_64 0:5.3.3-23.el6_4Dependency 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_4Complete!

使用YUM安装软件包


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


#  yum install httpdLoaded plugins: amazon-id, rhui-lb, securitySetting up Install ProcessResolving 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 ResolutionDependencies Resolved======================================================Package Arch Version Repository Size======================================================Installing:httpd x86_64 2.2.15-29.el6_4 rhui-REGION-rhel-server-releases 821 kInstalling for dependencies:apr x86_64 1.3.9-5.el6_2 rhui-REGION-rhel-server-releases 123 kapr-util x86_64 1.3.9-3.el6_0.1 rhui-REGION-rhel-server-releases 87 kapr-util-ldap x86_64 1.3.9-3.el6_0.1 rhui-REGION-rhel-server-releases 15 khttpd-tools x86_64 2.2.15-29.el6_4 rhui-REGION-rhel-server-releases 73 kTransaction Summary======================================================Install 5 Package(s)Total download size: 1.1 MInstalled size: 3.6 MIs this ok [y/N]: y

如你所见,在安装httpd时yum安装了额外的软件包。这称为yum完成的依赖包解析。


假如你不想让yum弹出[y/N]选项,可以使用yum install -y httpd


使用yum update 命令更新一个已存在的软件包


# yum update httpdLoaded plugins: amazon-id, rhui-lb, securitySetting up Update ProcessNo Packages marked for Update

这意味着你系统中安装的httpd软件包已经是yum软件仓库里的最新版本的了。


更新服务器上所有的软件包


# yum update

以上命令将系统上的所有软件包更新到最新版本,包括内核软件包,这意味着你的OS更新到了RHEL提供的最新版本了。


下载RPM软件包但是不安装


可以使用yum从RHEL或者CentOS的软件仓库里下载RPM软件包但是不安装。你首先需要下载一个插件让yum只下载rpm软件包而不安装。插件名字叫downloadonly,可以通过yum安装,如下所示:


# yum install yum-downloadonlyLoaded plugins: amazon-id, rhui-lb, securitySetting up Install ProcessResolving Dependencies-> Running transaction check--> Package yum-plugin-downloadonly.noarch 0:1.1.30-14.el6 will be installed-> Finished Dependency ResolutionDependencies Resolved====================================================Package Arch Version Repository Size====================================================Installing:yum-plugin-downloadonly noarch 1.1.30-14.el6 rhui-REGION-rhel-server-releases 20 kTransaction Summary====================================================Install 1 Package(s)Total download size: 20 kInstalled size: 21 kIs this ok [y/N]: yDownloading Packages:yum-plugin-downloadonly-1.1.30-14.el6.noarch.rpm | 20 kB 00:00Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionInstalling : yum-plugin-downloadonly-1.1.30-14.el6.noarch 1/1Verifying : yum-plugin-downloadonly-1.1.30-14.el6.noarch 1/1Installed:yum-plugin-downloadonly.noarch 0:1.1.30-14.el6Complete!

现在你就可以从软件仓库里只下载软件包而不安装了,命令如下:


# yum install httpd-devel -downloadonly

默认情况下软件包会被下载到/var/cache/yum/目录,但是你可以添加额外选项将其下载到指定位置


# yum install httpd-devel -downloadonly -downloaddir=/opt

假如你有一个rpm软件包但是没有它所依赖的软件包,你不知道到哪去得到它所依赖的软件包。你仍然可以通过yum安装这个rpm软件包,并从软件仓库里得到它所依赖的软件包。让我们安装刚刚下载的httpd-devel-2.2.15-29.el64.x8664 RPM软件包。


# yum localinstall /opt/httpd-devel-2.2.15-29.el6_4.x86_64.rpmLoaded plugins: amazon-id, downloadonly, rhui-lb, securitySetting up Local Package ProcessExamining /opt/httpd-devel-2.2.15-29.el6_4.x86_64.rpm: httpd-devel-2.2.15-29.el6_4.x86_64Marking /opt/httpd-devel-2.2.15-29.el6_4.x86_64.rpm to be installedResolving Dependencies-> Running transaction check--> Package httpd-devel.x86_64 0:2.2.15-29.el6_4 will be installed-> Processing Dependency: apr-devel for package: httpd-devel-2.2.15-29.el6_4.x86_64-> Processing Dependency: apr-util-devel for package: httpd-devel-2.2.15-29.el6_4.x86_64-> Running transaction check--> Package apr-devel.x86_64 0:1.3.9-5.el6_2 will be installed--> Package apr-util-devel.x86_64 0:1.3.9-3.el6_0.1 will be installed-> Processing Dependency: openldap-devel for package: apr-util-devel-1.3.9-3.el6_0.1.x86_64-> Processing Dependency: expat-devel for package: apr-util-devel-1.3.9-3.el6_0.1.x86_64-> Processing Dependency: db4-devel for package: apr-util-devel-1.3.9-3.el6_0.1.x86_64-> Running transaction check--> Package db4-devel.x86_64 0:4.7.25-18.el6_4 will be installed-> Processing Dependency: db4-cxx = 4.7.25-18.el6_4 for package: db4-devel-4.7.25-18.el6_4.x86_64-> Processing Dependency: db4 = 4.7.25-18.el6_4 for package: db4-devel-4.7.25-18.el6_4.x86_64-> Processing Dependency: libdb_cxx-4.7.so()(64bit) for package: db4-devel-4.7.25-18.el6_4.x86_64--> Package expat-devel.x86_64 0:2.0.1-11.el6_2 will be installed--> Package openldap-devel.x86_64 0:2.4.23-32.el6_4.1 will be installed-> Processing Dependency: cyrus-sasl-devel >= 2.1 for package: openldap-devel-2.4.23-32.el6_4.1.x86_64-> Running transaction check--> Package cyrus-sasl-devel.x86_64 0:2.1.23-13.el6_3.1 will be installed--> Package db4.x86_64 0:4.7.25-17.el6 will be updated-> Processing Dependency: db4 = 4.7.25-17.el6 for package: db4-utils-4.7.25-17.el6.x86_64--> Package db4.x86_64 0:4.7.25-18.el6_4 will be an update--> Package db4-cxx.x86_64 0:4.7.25-18.el6_4 will be installed-> Running transaction check--> Package db4-utils.x86_64 0:4.7.25-17.el6 will be updated--> Package db4-utils.x86_64 0:4.7.25-18.el6_4 will be an update-> Finished Dependency ResolutionDependencies Resolved===================================================Package Arch Version Repository Size===================================================Installing:httpd-devel x86_64 2.2.15-29.el6_4 /httpd-devel-2.2.15-29.el6_4.x86_64 526 kInstalling for dependencies:apr-devel x86_64 1.3.9-5.el6_2 rhui-REGION-rhel-server-releases 176 kapr-util-devel x86_64 1.3.9-3.el6_0.1 rhui-REGION-rhel-server-releases 69 kcyrus-sasl-devel x86_64 2.1.23-13.el6_3.1 rhui-REGION-rhel-server-releases 302 kdb4-cxx x86_64 4.7.25-18.el6_4 rhui-REGION-rhel-server-releases 588 kdb4-devel x86_64 4.7.25-18.el6_4 rhui-REGION-rhel-server-releases 6.6 Mexpat-devel x86_64 2.0.1-11.el6_2 rhui-REGION-rhel-server-releases 120 kopenldap-devel x86_64 2.4.23-32.el6_4.1 rhui-REGION-rhel-server-releases 1.1 MUpdating for dependencies:db4 x86_64 4.7.25-18.el6_4 rhui-REGION-rhel-server-releases 563 kdb4-utils x86_64 4.7.25-18.el6_4 rhui-REGION-rhel-server-releases 130 kTransaction Summary===============================================Install 8 Package(s)Upgrade 2 Package(s)Total size: 10 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionUpdating : db4-4.7.25-18.el6_4.x86_64 1/12Installing : apr-devel-1.3.9-5.el6_2.x86_64 2/12Installing : expat-devel-2.0.1-11.el6_2.x86_64 3/12Installing : db4-cxx-4.7.25-18.el6_4.x86_64 4/12Installing : db4-devel-4.7.25-18.el6_4.x86_64 5/12Installing : cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64 6/12Installing : openldap-devel-2.4.23-32.el6_4.1.x86_64 7/12Installing : apr-util-devel-1.3.9-3.el6_0.1.x86_64 8/12Installing : httpd-devel-2.2.15-29.el6_4.x86_64 9/12Updating : db4-utils-4.7.25-18.el6_4.x86_64 10/12Cleanup : db4-utils-4.7.25-17.el6.x86_64 11/12Cleanup : db4-4.7.25-17.el6.x86_64 12/12Verifying : apr-devel-1.3.9-5.el6_2.x86_64 1/12Verifying : cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64 2/12Verifying : apr-util-devel-1.3.9-3.el6_0.1.x86_64 3/12Verifying : db4-cxx-4.7.25-18.el6_4.x86_64 4/12Verifying : httpd-devel-2.2.15-29.el6_4.x86_64 5/12Verifying : openldap-devel-2.4.23-32.el6_4.1.x86_64 6/12Verifying : expat-devel-2.0.1-11.el6_2.x86_64 7/12Verifying : db4-devel-4.7.25-18.el6_4.x86_64 8/12Verifying : db4-4.7.25-18.el6_4.x86_64 9/12Verifying : db4-utils-4.7.25-18.el6_4.x86_64 10/12Verifying : db4-4.7.25-17.el6.x86_64 11/12Verifying : db4-utils-4.7.25-17.el6.x86_64 12/12Installed:httpd-devel.x86_64 0:2.2.15-29.el6_4Dependency Installed:apr-devel.x86_64 0:1.3.9-5.el6_2 apr-util-devel.x86_64 0:1.3.9-3.el6_0.1cyrus-sasl-devel.x86_64 0:2.1.23-13.el6_3.1 db4-cxx.x86_64 0:4.7.25-18.el6_4db4-devel.x86_64 0:4.7.25-18.el6_4 expat-devel.x86_64 0:2.0.1-11.el6_2openldap-devel.x86_64 0:2.4.23-32.el6_4.1Dependency Updated:db4.x86_64 0:4.7.25-18.el6_4 db4-utils.x86_64 0:4.7.25-18.el6_4Complete!

使用yum卸载软件包


使用 yum remove 卸载软件包。举例如下:


# yum remove httpdFailed to set locale, defaulting to CLoaded plugins: amazon-id, downloadonly, rhui-lb, securitySetting up Remove ProcessResolving Dependencies-> Running transaction check--> Package httpd.x86_64 0:2.2.15-29.el6_4 will be erased-> Processing Dependency: httpd-mmn = 20051115 for package: php-5.3.3-23.el6_4.x86_64-> Processing Dependency: httpd = 2.2.15-29.el6_4 for package: httpd-devel-2.2.15-29.el6_4.x86_64-> Running transaction check--> Package httpd-devel.x86_64 0:2.2.15-29.el6_4 will be erased--> Package php.x86_64 0:5.3.3-23.el6_4 will be erased-> Finished Dependency ResolutionDependencies Resolved================================================Package Arch Version Repository Size================================================Removing:httpd x86_64 2.2.15-29.el6_4 @rhui-REGION-rhel-server-releases 2.9 MRemoving for dependencies:httpd-devel x86_64 2.2.15-29.el6_4 @/httpd-devel-2.2.15-29.el6_4.x86_64 526 kphp x86_64 5.3.3-23.el6_4 @rhui-REGION-rhel-server-releases 3.5 MTransaction Summary================================================Remove 3 Package(s)Installed size: 7.0 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionErasing : httpd-devel-2.2.15-29.el6_4.x86_64 1/3Erasing : php-5.3.3-23.el6_4.x86_64 2/3Erasing : httpd-2.2.15-29.el6_4.x86_64 3/3Verifying : httpd-2.2.15-29.el6_4.x86_64 1/3Verifying : httpd-devel-2.2.15-29.el6_4.x86_64 2/3Verifying : php-5.3.3-23.el6_4.x86_64 3/3Removed:httpd.x86_64 0:2.2.15-29.el6_4Dependency Removed:httpd-devel.x86_64 0:2.2.15-29.el6_4 php.x86_64 0:5.3.3-23.el6_4Complete!

列出所有安装的软件包


假如你要列出你系统上安装的所有软件包,你可以使用yum list installed命令。这条命令结合grep命令是非常有用的,可以用来检查某个特定的软件包是否已被安装。这与使用rpm -qa命令询问已经安装的软件包相似。


# yum list installedLoaded plugins: amazon-id, downloadonly, rhui-lb, securityInstalled PackagesConsoleKit.x86_64 0.4.1-3.el6 @koji-override-0/$releaseverConsoleKit-libs.x86_64 0.4.1-3.el6 @koji-override-0/$releaseverMAKEDEV.x86_64 3.24-6.el6 @koji-override-0/$releaseverPyYAML.x86_64 3.10-3.1.el6 @koji-override-0/$releaseverRed_Hat_Enterprise_Linux-Release_Notes-6-en-US.noarch4-2.el6 @koji-override-0/$releaseverSDL.x86_64 1.2.14-3.el6 @koji-override-0/$releaseverabrt.x86_64 2.0.8-15.el6 @koji-override-0/$releaseverabrt-addon-ccpp.x86_64 2.0.8-15.el6 @koji-override-0/$releaseverabrt-addon-kerneloops.x86_64 2.0.8-15.el6 @koji-override-0/$releaseverabrt-addon-python.x86_64 2.0.8-15.el6 @koji-override-0/$releaseverabrt-cli.x86_64 2.0.8-15.el6 @koji-override-0/$releaseverabrt-libs.x86_64 2.0.8-15.el6 @koji-override-0/$releaseverabrt-tui.x86_64 2.0.8-15.el6 @koji-override-0/$releaseveracl.x86_64 2.2.49-6.el6 @koji-override-0/$releaseveracpid.x86_64 1.0.10-2.1.el6 @koji-override-0/$releaseveraic94xx-firmware.noarch 30-2.el6 @koji-override-0/$releasever..Output Truncated.

列出可用的软件库,通过它们可以查询、安装和更新软件包


# yum repolistLoaded plugins: amazon-id, downloadonly, rhui-lb, securityrepo id repo name statusrhui-REGION-client-config-server-6 Red Hat Update Infrastructure 2.0 Client Configuration Server 6 4rhui-REGION-rhel-server-releases Red Hat Enterprise Linux Server 6 (RPMs) 10994rhui-REGION-rhel-server-releases-optional Red Hat Enterprise Linux Server 6 Optional (RPMs) 6250repolist: 17248


via: http://linoxide.com/linux-command/package-management-yum-redhat-linux/

译者:Linux-pdz 校对:jasminepeng


酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部