在了解 YUM 之前我们先来简单介绍下 RPM ,什么是 RPM ? Redhat Package Manager 红帽包管理者;就像在 windows 中安装 .exe 一样,不过在安装 RPM 的时候会有很多的依赖关系,比如我们需要安装 MYSQL 软件包就需要安装其他一系列的其他软件例如:    

[root@localhost Server]# rpm -ivh MySQL-python-1.2.1-1.i386.rpm
warning: MySQL-python-1.2.1-1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: Failed dependencies:
        libmysqlclient_r.so.15 is needed by MySQL-python-1.2.1-1.i386
        libmysqlclient_r.so.15(libmysqlclient_15) is needed by MySQL-python-1.2.1-1.i386
        mx is needed by MySQL-python-1.2.1-1.i386
        mysql is needed by MySQL-python-1.2.1-1.i386

 

        我们需要安装前面的几个具有依赖关系的数据包,而这些数据包需要手动的一个一个安装,非常的麻烦,而YUM能够解决RPM的依赖关系。

      Yum ( Yellow dog Updater, Modified )翻译成中文的意思就是黄狗软件升级工具。RHEL5.1以后的版本才默认安装的,之前的版本需要安装YUM软件包才能使用。

    YUM不但解决了RPM软件包依赖关系,而且还方便更新,删除RPM包,同时也便于管理大量系统的更新问题。

    由于本人环境有限,只有个RHEL5的虚拟机,之前版本的虚拟机被卸载了,而卸载YUM又需要卸载很多相关的依赖包,所以就没卸载

[root@localhost Server]# rpm -e yum
error: Failed dependencies:
        yum >= 3.2.18 is needed by (installed) yum-security-1.1.16-13.el5.noarch
        yum >= 3.2.19-15 is needed by (installed) yum-rhn-plugin-0.5.3-30.el5.noarch
        yum >= 3.2.0 is needed by (installed) yum-updatesd-0.9-2.el5.noarch
        yum >= 3.2.5-2 is needed by (installed) pirut-1.3.28-13.el5.noarch

没有安装yum的可以安装一下,我就直接用RHEL5的默认安装的了。

   按照Linux国际化的标准,同所有的服务一样都有/etc/yum.conf这样一个配置文件。我们看下:

[root@localhost Server]# cat /etc/yum.conf |grep -v ^#
[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1 
metadata_expire=1h[mail]                                     声明以下是为YUM所作的选项 
   
  

    cachedir                                是缓存存放的路径 
  
 
  

    keepcache                            是指当安装完成后时候把该包的信息缓存下来 
  
 
  

    debuglevel                           是错误级别 
  
 
  

    logfile                                    是yum软件日志的存放路径 
  
 
  

    distroverpkg                         根据什么确定包的版本 
  
 
  

    tolerant                                  是否提示包安装信息错误 
  
 
  

    exactarch                               根据CUP的架构来确定是否安装包 
  
 
  

    obsoletes                              yum升级相关选项 
  
 
  

    gpgcheck                              时候检查包的签名 
  
 
  

    plugins                                  是否添加插件功能 
  
 
  

    metadata_expire                    过期时间 
  
 
  
[root@localhost Server]# cat /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///mnt/Server/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release 
     
  
[  ]                                         里面的源的名字
 
  

    name                                     对库描述 
  
 
  

    baseurl                                 下载源的URL路径 
  
 
  

    enabled                                能否使用这个数据库 
  
 
  

    gpgcheck                             同主配置文件一样,检查包的签名 
  
 
  

    gpgkey                                 签名的URL路径



刚刚中间提到了一个源的词;究竟什么是源?这个源就是下载源,把需要的RPM包做一个依赖关系的处理,createrepo创建源的命令不过需要使用RPM安装一下createrepo包才行,企5的DVD光盘中默认就存在这个源。

[root@localhost Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:createrepo             ########################################### [100%]



所有的配置就告一段落,下面就介绍下常用命令

yum install 包名→→→→→→→→安装包

yum update 包名→→→→→→→→升级包

yum remove 包名→→→→→→→→删除包

yum list 包名→→→→→→→→→→查询包的信息

yum clean all→→→→→→→→→→清空缓存信息

*******************************************************************

实例安装GCC

[root@localhost /]# umount /dev/cdrom
[root@localhost /]# mount /dev/cdrom /mnt/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost /]# vim /etc/yum.repos.d/rhel-debuginfo.repo 
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///mnt/Server/
enabled=1
gpgcheck=0
:wq
[root@localhost /]# yum install gcc*
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package gcc-java.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: libgcj-devel = 4.1.2-44.el5 for package: gcc-java
---> Package gcc-gfortran.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: libgfortran = 4.1.2-44.el5 for package: gcc-gfortran
--> Processing Dependency: libgfortran.so.1 for package: gcc-gfortran
---> Package gcc43-gfortran.i386 0:4.3.2-7.el5 set to be updated
--> Processing Dependency: libgfortran43 = 4.3.2-7.el5 for package: gcc43-gfortran
--> Processing Dependency: libgfortran.so.3 for package: gcc43-gfortran
---> Package gcc-c++.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: libstdc++-devel = 4.1.2-44.el5 for package: gcc-c++
---> Package gcc.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: libgomp >= 4.1.2-44.el5 for package: gcc
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc
---> Package gcc43.i386 0:4.3.2-7.el5 set to be updated
---> Package gcc-gnat.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: libgnat = 4.1.2-44.el5 for package: gcc-gnat
--> Processing Dependency: libgnat-4.1.so for package: gcc-gnat
--> Processing Dependency: libgnarl-4.1.so for package: gcc-gnat
---> Package gcc-objc.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: libobjc = 4.1.2-44.el5 for package: gcc-objc
--> Processing Dependency: libobjc.so.1 for package: gcc-objc
---> Package gcc43-c++.i386 0:4.3.2-7.el5 set to be updated
--> Processing Dependency: libstdc++43-devel = 4.3.2-7.el5 for package: gcc43-c++
---> Package gcc-objc++.i386 0:4.1.2-44.el5 set to be updated
--> Running transaction check
---> Package libgomp.i386 0:4.3.2-7.el5 set to be updated
---> Package glibc-devel.i386 0:2.5-34 set to be updated
--> Processing Dependency: glibc-headers = 2.5-34 for package: glibc-devel
--> Processing Dependency: glibc-headers for package: glibc-devel
---> Package libgfortran43.i386 0:4.3.2-7.el5 set to be updated
---> Package libgnat.i386 0:4.1.2-44.el5 set to be updated
---> Package libobjc.i386 0:4.1.2-44.el5 set to be updated
---> Package libstdc++-devel.i386 0:4.1.2-44.el5 set to be updated
---> Package libgcj-devel.i386 0:4.1.2-44.el5 set to be updated
--> Processing Dependency: zlib-devel for package: libgcj-devel
--> Processing Dependency: /usr/lib/libz.so for package: libgcj-devel
---> Package libstdc++43-devel.i386 0:4.3.2-7.el5 set to be updated
---> Package libgfortran.i386 0:4.1.2-44.el5 set to be updated
--> Running transaction check
---> Package zlib-devel.i386 0:1.2.3-3 set to be updated
---> Package glibc-headers.i386 0:2.5-34 set to be updated
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
--> Processing Dependency: kernel-headers for package: glibc-headers
--> Running transaction check
---> Package kernel-headers.i386 0:2.6.18-128.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================
 Package               Arch     Version            Repository          Size
============================================================================
Installing:
 gcc                   i386     4.1.2-44.el5       rhel-debuginfo     5.2 M
 gcc-c++               i386     4.1.2-44.el5       rhel-debuginfo     3.4 M
 gcc-gfortran          i386     4.1.2-44.el5       rhel-debuginfo     3.1 M
 gcc-gnat              i386     4.1.2-44.el5       rhel-debuginfo      11 M
 gcc-java              i386     4.1.2-44.el5       rhel-debuginfo     2.9 M
 gcc-objc              i386     4.1.2-44.el5       rhel-debuginfo     2.6 M
 gcc-objc++            i386     4.1.2-44.el5       rhel-debuginfo     2.8 M
 gcc43                 i386     4.3.2-7.el5        rhel-debuginfo     8.1 M
 gcc43-c++             i386     4.3.2-7.el5        rhel-debuginfo     3.8 M
 gcc43-gfortran        i386     4.3.2-7.el5        rhel-debuginfo     3.7 M
Installing for dependencies:
 glibc-devel           i386     2.5-34             rhel-debuginfo     2.0 M
 glibc-headers         i386     2.5-34             rhel-debuginfo     598 k
 kernel-headers        i386     2.6.18-128.el5     rhel-debuginfo     912 k
 libgcj-devel          i386     4.1.2-44.el5       rhel-debuginfo     1.4 M
 libgfortran           i386     4.1.2-44.el5       rhel-debuginfo     231 k
 libgfortran43         i386     4.3.2-7.el5        rhel-debuginfo     240 k
 libgnat               i386     4.1.2-44.el5       rhel-debuginfo     989 k
 libgomp               i386     4.3.2-7.el5        rhel-debuginfo      67 k
 libobjc               i386     4.1.2-44.el5       rhel-debuginfo     102 k
 libstdc++-devel       i386     4.1.2-44.el5       rhel-debuginfo     2.9 M
 libstdc++43-devel     i386     4.3.2-7.el5        rhel-debuginfo     3.9 M
 zlib-devel            i386     1.2.3-3            rhel-debuginfo     100 k
Transaction Summary
============================================================================
Install     22 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 60 M
Is this ok [y/N]:y
Downloading Packages:
------------------------------------------------------------------------------
Total                                         1.3 GB/s |  60 MB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : libgomp                                         [ 1/22]
  Installing     : libgnat                                         [ 2/22]
  Installing     : libgfortran                                     [ 3/22]
  Installing     : libgfortran43                                   [ 4/22]
  Installing     : libobjc                                         [ 5/22]
  Installing     : libstdc++43-devel                               [ 6/22]
  Installing     : kernel-headers                                  [ 7/22]
  Installing     : glibc-headers                                   [ 8/22]
  Installing     : glibc-devel                                     [ 9/22]
  Installing     : libstdc++-devel                                 [10/22]
  Installing     : zlib-devel                                      [11/22]
  Installing     : gcc                                             [12/22]
  Installing     : gcc43                                           [13/22]
  Installing     : libgcj-devel                                    [14/22]
  Installing     : gcc-objc                                        [15/22]
  Installing     : gcc-c++                                         [16/22]
  Installing     : gcc-gfortran                                    [17/22]
  Installing     : gcc-java                                        [18/22]
  Installing     : gcc-objc++                                      [19/22]
  Installing     : gcc-gnat                                        [20/22]
  Installing     : gcc43-c++                                       [21/22]
  Installing     : gcc43-gfortran                                  [22/22]
Installed: gcc.i386 0:4.1.2-44.el5 gcc-c++.i386 0:4.1.2-44.el5 gcc-gfortran.i386 0:4.1.2-44.el5 gcc-gnat.i386 0:4.1.2-44.el5 gcc-java.i386 0:4.1.2-44.el5 gcc-objc.i386 0:4.1.2-44.el5 gcc-objc++.i386 0:4.1.2-44.el5 gcc43.i386 0:4.3.2-7.el5 gcc43-c++.i386 0:4.3.2-7.el5 gcc43-gfortran.i386 0:4.3.2-7.el5
Dependency Installed: glibc-devel.i386 0:2.5-34 glibc-headers.i386 0:2.5-34 kernel-headers.i386 0:2.6.18-128.el5 libgcj-devel.i386 0:4.1.2-44.el5 libgfortran.i386 0:4.1.2-44.el5 libgfortran43.i386 0:4.3.2-7.el5 libgnat.i386 0:4.1.2-44.el5 libgomp.i386 0:4.3.2-7.el5 libobjc.i386 0:4.1.2-44.el5 libstdc++-devel.i386 0:4.1.2-44.el5 libstdc++43-devel.i386 0:4.3.2-7.el5 zlib-devel.i386 0:1.2.3-3
Complete!



------------------------------------------------------------------------------------------



凭借自己二把刀的水平写出来的,如果您发现那里有错误请通知我



                                                                             谢谢      O(∩_∩)O~


转载于:https://blog.51cto.com/xiaoqi01/241142