23-Linux-软件包管理-YUM

来源:互联网 发布:每天最佳健身时间 知乎 编辑:程序博客网 时间:2024/05/22 01:25



由来

    RPM软件包形式管理软件虽然方便, 但是需要手工解决软件包的依赖关系.
    有时安装一个软件需要首先安装几十上百个其他软件, 手工解决则过于复杂.
    YUM的出现就是为了解决这个问题的.


说明

    YUM, Yellowdog Updater Modified.
    是一个RPM的前端程序, 主要作用就是 自动解决RPM的依赖关系.


特点

    自动解决依赖关系
    可以对RPM进行分组, 以组为单位进行批量安装操作
    引入仓库的概念, 且支持多个仓库
    配置简单


仓库

    说明

        repository, repo
        仓库 存放着大量的RPM软件包,
        当使用YUM安装一个RPM包时, 会自动在仓库中查找依赖软件并安装.


    仓库类型

        本地的
            通过 FILE协议 方式访问
        网络的
            通过 HTTP、FTP、NFS协议 方式访问


    配置文件

        位置: /etc/yum.repos.d
        格式
            [仓库名称]
            name = 仓库的描述信息
            baseurl = http://www.foo.org/yum/rpms
            enabled = 0或1, 该仓库是否启用, 默认为1
            gpgcheck = 0或1, 是否校验
        注意
            YUM配置文件必须以".repo"结尾
            一个配置文件可以配置多个仓库
            /etc/yum.repos.d 目录下可以存在多个配置文件
        示例 : /etc/yum.repos.d/CentOS-Base.repo
[root@wuqinfei yum.repos.d]# pwd/etc/yum.repos.d[root@wuqinfei yum.repos.d]# ls -ltotal 16-rw-r--r--. 1 root root 1926 Jun 26  2012 CentOS-Base.repo-rw-r--r--. 1 root root  637 Jun 26  2012 CentOS-Debuginfo.repo-rw-r--r--. 1 root root  626 Jun 26  2012 CentOS-Media.repo-rw-r--r--. 1 root root 2593 Jun 26  2012 CentOS-Vault.repo[root@wuqinfei yum.repos.d]# vim CentOS-Base.repo# CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client.  You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist= does not work for you, as a fall back you can try the# remarked out baseurl= line instead.##[base]name=CentOS-$releasever - Basemirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6#released updates[updates]name=CentOS-$releasever - Updatesmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6



基本命令

    yum install software-name   安装指定软件

[root@wuqinfei yum.repos.d]# yum install tigervncLoaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cnSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package tigervnc.i686 0:1.1.0-8.el6_5 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package           Arch          Version                 Repository        Size================================================================================Installing: tigervnc          i686          1.1.0-8.el6_5           updates          266 kTransaction Summary================================================================================Install       1 Package(s)Total download size: 266 kInstalled size: 683 kIs this ok [y/N]: yDownloading Packages:tigervnc-1.1.0-8.el6_5.i686.rpm                          | 266 kB     00:06warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEYRetrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6Importing GPG key 0xC105B9DE: Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org> Package: centos-release-6-3.el6.centos.9.i686 (@anaconda-CentOS-201207051201.i386/6.3) From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6Is this ok [y/N]: yRunning rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : tigervnc-1.1.0-8.el6_5.i686                                  1/1  Verifying  : tigervnc-1.1.0-8.el6_5.i686                                  1/1Installed:  tigervnc.i686 0:1.1.0-8.el6_5Complete![root@wuqinfei yum.repos.d]# rpm -qi tigervncName        : tigervnc                     Relocations: (not relocatable)Version     : 1.1.0                             Vendor: CentOSRelease     : 8.el6_5                       Build Date: Tue 04 Feb 2014 01:21:41 PM CSTInstall Date: Sun 09 Feb 2014 10:16:27 PM CST      Build Host: c6b9.bsys.dev.centos.orgGroup       : User Interface/Desktops       Source RPM: tigervnc-1.1.0-8.el6_5.src.rpmSize        : 699901                           License: GPLv2+Signature   : RSA/SHA1, Tue 04 Feb 2014 01:35:59 PM CST, Key ID 0946fca2c105b9dePackager    : CentOS BuildSystem <http://bugs.centos.org>URL         : http://www.tigervnc.comSummary     : A TigerVNC remote display systemDescription :Virtual Network Computing (VNC) is a remote display system whichallows you to view a computing 'desktop' environment not only on themachine where it is running, but from anywhere on the Internet andfrom a wide variety of machine architectures.  This package contains aclient which will allow you to connect to other desktops running a VNCserver.


    yum remove software-name    卸载~

[root@wuqinfei yum.repos.d]# yum remove tigervncLoaded plugins: fastestmirror, refresh-packagekit, securitySetting up Remove ProcessResolving Dependencies--> Running transaction check---> Package tigervnc.i686 0:1.1.0-8.el6_5 will be erased--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package           Arch          Version                Repository         Size================================================================================Removing: tigervnc          i686          1.1.0-8.el6_5          @updates          683 kTransaction Summary================================================================================Remove        1 Package(s)Installed size: 683 kIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Erasing    : tigervnc-1.1.0-8.el6_5.i686                                  1/1  Verifying  : tigervnc-1.1.0-8.el6_5.i686                                  1/1Removed:  tigervnc.i686 0:1.1.0-8.el6_5Complete!


    yum update software-name    升级~
    示例: 安装 gcc
[root@wuqinfei yum.repos.d]# yum install gcc.i686Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cnSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package gcc.i686 0:4.4.7-4.el6 will be installed--> Processing Dependency: libgomp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.i686--> Processing Dependency: cpp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.i686--> Processing Dependency: libgcc >= 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.i686--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.4.7-4.el6.i686--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-4.el6.i686--> Running transaction check---> Package cloog-ppl.i686 0:0.15.7-1.2.el6 will be installed--> Processing Dependency: libppl_c.so.2 for package: cloog-ppl-0.15.7-1.2.el6.i686--> Processing Dependency: libppl.so.7 for package: cloog-ppl-0.15.7-1.2.el6.i686---> Package cpp.i686 0:4.4.7-4.el6 will be installed--> Processing Dependency: libmpfr.so.1 for package: cpp-4.4.7-4.el6.i686---> Package glibc-devel.i686 0:2.12-1.132.el6 will be installed--> Processing Dependency: glibc-headers = 2.12-1.132.el6 for package: glibc-devel-2.12-1.132.el6.i686--> Processing Dependency: glibc = 2.12-1.132.el6 for package: glibc-devel-2.12-1.132.el6.i686--> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.132.el6.i686---> Package libgcc.i686 0:4.4.6-4.el6 will be updated---> Package libgcc.i686 0:4.4.7-4.el6 will be an update---> Package libgomp.i686 0:4.4.6-4.el6 will be updated---> Package libgomp.i686 0:4.4.7-4.el6 will be an update--> Running transaction check---> Package glibc.i686 0:2.12-1.80.el6 will be updated--> Processing Dependency: glibc = 2.12-1.80.el6 for package: glibc-common-2.12-1.80.el6.i686---> Package glibc.i686 0:2.12-1.132.el6 will be an update---> Package glibc-headers.i686 0:2.12-1.132.el6 will be installed--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.132.el6.i686--> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.132.el6.i686---> Package mpfr.i686 0:2.4.1-6.el6 will be installed---> Package ppl.i686 0:0.10.2-11.el6 will be installed--> Running transaction check---> Package glibc-common.i686 0:2.12-1.80.el6 will be updated---> Package glibc-common.i686 0:2.12-1.132.el6 will be an update---> Package kernel-headers.i686 0:2.6.32-431.3.1.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package              Arch       Version                    Repository     Size================================================================================Installing: gcc                  i686       4.4.7-4.el6                base          8.2 MInstalling for dependencies: cloog-ppl            i686       0.15.7-1.2.el6             base           93 k cpp                  i686       4.4.7-4.el6                base          3.4 M glibc-devel          i686       2.12-1.132.el6             base          978 k glibc-headers        i686       2.12-1.132.el6             base          616 k kernel-headers       i686       2.6.32-431.3.1.el6         updates       2.8 M mpfr                 i686       2.4.1-6.el6                base          153 k ppl                  i686       0.10.2-11.el6              base          1.3 MUpdating for dependencies: glibc                i686       2.12-1.132.el6             base          4.3 M glibc-common         i686       2.12-1.132.el6             base           14 M libgcc               i686       4.4.7-4.el6                base          112 k libgomp              i686       4.4.7-4.el6                base          121 kTransaction Summary================================================================================Install       8 Package(s)Upgrade       4 Package(s)Total download size: 36 MIs this ok [y/N]: yDownloading Packages:(1/12): cloog-ppl-0.15.7-1.2.el6.i686.rpm                |  93 kB     00:00(2/12): cpp-4.4.7-4.el6.i686.rpm                         | 3.4 MB     00:58(3/12): gcc-4.4.7-4.el6.i686.rpm                         | 8.2 MB     02:20(4/12): glibc-2.12-1.132.el6.i686.rpm                    | 4.3 MB     00:57(5/12): glibc-common-2.12-1.132.el6.i686.rpm             |  14 MB     03:39(6/12): glibc-devel-2.12-1.132.el6.i686.rpm              | 978 kB     00:14(7/12): glibc-headers-2.12-1.132.el6.i686.rpm            | 616 kB     00:07(8/12): kernel-headers-2.6.32-431.3.1.el6.i686.rpm       | 2.8 MB     00:38(9/12): libgcc-4.4.7-4.el6.i686.rpm                      | 112 kB     00:01(10/12): libgomp-4.4.7-4.el6.i686.rpm                    | 121 kB     00:01(11/12): mpfr-2.4.1-6.el6.i686.rpm                       | 153 kB     00:01(12/12): ppl-0.10.2-11.el6.i686.rpm                      | 1.3 MB     00:16--------------------------------------------------------------------------------Total                                            66 kB/s |  36 MB     09:20Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : kernel-headers-2.6.32-431.3.1.el6.i686                      1/16  Updating   : libgcc-4.4.7-4.el6.i686                                     2/16  Updating   : glibc-common-2.12-1.132.el6.i686                            3/16  Updating   : glibc-2.12-1.132.el6.i686                                   4/16  Installing : glibc-headers-2.12-1.132.el6.i686                           5/16  Installing : glibc-devel-2.12-1.132.el6.i686                             6/16  Installing : ppl-0.10.2-11.el6.i686                                      7/16  Installing : cloog-ppl-0.15.7-1.2.el6.i686                               8/16  Installing : mpfr-2.4.1-6.el6.i686                                       9/16  Installing : cpp-4.4.7-4.el6.i686                                       10/16  Updating   : libgomp-4.4.7-4.el6.i686                                   11/16  Installing : gcc-4.4.7-4.el6.i686                                       12/16  Cleanup    : libgomp-4.4.6-4.el6.i686                                   13/16  Cleanup    : glibc-common-2.12-1.80.el6.i686                            14/16  Cleanup    : glibc-2.12-1.80.el6.i686                                   15/16  Cleanup    : libgcc-4.4.6-4.el6.i686                                    16/16  Verifying  : glibc-devel-2.12-1.132.el6.i686                             1/16  Verifying  : ppl-0.10.2-11.el6.i686                                      2/16  Verifying  : kernel-headers-2.6.32-431.3.1.el6.i686                      3/16  Verifying  : gcc-4.4.7-4.el6.i686                                        4/16  Verifying  : glibc-headers-2.12-1.132.el6.i686                           5/16  Verifying  : libgcc-4.4.7-4.el6.i686                                     6/16  Verifying  : glibc-2.12-1.132.el6.i686                                   7/16  Verifying  : mpfr-2.4.1-6.el6.i686                                       8/16  Verifying  : libgomp-4.4.7-4.el6.i686                                    9/16  Verifying  : glibc-common-2.12-1.132.el6.i686                           10/16  Verifying  : cpp-4.4.7-4.el6.i686                                       11/16  Verifying  : cloog-ppl-0.15.7-1.2.el6.i686                              12/16  Verifying  : libgcc-4.4.6-4.el6.i686                                    13/16  Verifying  : libgomp-4.4.6-4.el6.i686                                   14/16  Verifying  : glibc-common-2.12-1.80.el6.i686                            15/16  Verifying  : glibc-2.12-1.80.el6.i686                                   16/16Installed:  gcc.i686 0:4.4.7-4.el6Dependency Installed:  cloog-ppl.i686 0:0.15.7-1.2.el6           cpp.i686 0:4.4.7-4.el6  glibc-devel.i686 0:2.12-1.132.el6         glibc-headers.i686 0:2.12-1.132.el6  kernel-headers.i686 0:2.6.32-431.3.1.el6  mpfr.i686 0:2.4.1-6.el6  ppl.i686 0:0.10.2-11.el6Dependency Updated:  glibc.i686 0:2.12-1.132.el6         glibc-common.i686 0:2.12-1.132.el6  libgcc.i686 0:4.4.7-4.el6           libgomp.i686 0:4.4.7-4.el6Complete!



YUM查询

    yum search keyword  : 搜索包含该关键字的rpm包

[root@wuqinfei yum.repos.d]# yum search gccLoaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cn=============================== N/S Matched: gcc ===============================compat-libgcc-296.i686 : Compatibility 2.96-RH libgcc librarygcc-c++.i686 : C++ support for GCCgcc-gnat.i686 : Ada 95 support for GCCgcc-java.i686 : Java support for GCCgcc-objc.i686 : Objective-C support for GCCgcc-objc++.i686 : Objective-C++ support for GCClibgcc.i686 : GCC version 4.4 shared support librarycompat-gcc-34.i686 : Compatibility GNU Compiler Collectioncompat-gcc-34-c++.i686 : C++ support for compatibility compilercompat-gcc-34-g77.i686 : Fortran 77 support for compatibility compilergcc.i686 : Various compilers (C, C++, Objective-C, Java, ...)gcc-gfortran.i686 : Fortran supportlibgcj.i686 : Java runtime library for gcclibgcj-devel.i686 : Libraries for Java development using GCClibgcj-src.i686 : Java library sources from GCC4 previewlibgomp.i686 : GCC OpenMP v3.0 shared support librarylibmudflap.i686 : GCC mudflap shared support librarylibmudflap-devel.i686 : GCC mudflap support  Name and summary matches only, use "search all" for everything.


    yum list (all | installed | recent | updates) 
        列出 所有的/已安装的/最近的/更新的
    yum info packagename : 显示指定软件的信息

[root@wuqinfei yum.repos.d]# yum info gcc.i686Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cnAvailable PackagesName        : gccArch        : i686Version     : 4.4.7Release     : 4.el6Size        : 8.2 MRepo        : baseSummary     : Various compilers (C, C++, Objective-C, Java, ...)URL         : http://gcc.gnu.orgLicense     : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptionsDescription : The gcc package contains the GNU Compiler Collection version 4.4.            : You'll need this package in order to compile C code.


    yum whatprovides filename : 查询包含指定文件的rpm软件


创建yum仓库

    1) 将所有rpm文件拷贝到 仓库(某个目录)
    2) 安装 createrepo 软件(通过rpm命令)
    3) 运行 createrepo命令
        作用: 创建repodata目录, 存放索引文件
        createrepo -v /rpm-directory
    4) 注: 如果有分组信息, 则在运行命令时使用 "-g" 来指定分组文件
        createrepo -g /tmp/*comps.xml/rpm-directory
        CentOS/RHEL的分组信息保存于光盘 repodata/目录下
            文件名以 "comps.xml"结尾的xml文件
    5) 使用
        本地 : FILE协议
        网路 : HTTP FTP NFS
    示例
        1) 查看 CentOS_6.3 光盘中的 仓库Packages(所有rpm包)
            
        2) 创建本地仓库目录"/wuqinfei-yum-repo", 并将 Packages中的rpm包考进来
        3) 安装 createrepo软件

[root@wuqinfei ~]# yum search createrepoLoaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cn=========================== N/S Matched: createrepo ============================createrepo.noarch : Creates a common metadata repository  Name and summary matches only, use "search all" for everything.[root@wuqinfei ~]# yum install createrepo.noarchLoaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cnSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package createrepo.noarch 0:0.9.9-18.el6 will be installed--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-18.el6.noarch--> Running transaction check---> Package python-deltarpm.i686 0:3.5-0.5.20090913git.el6 will be installed--> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 for package: python-deltarpm-3.5-0.5.20090913git.el6.i686--> Running transaction check---> Package deltarpm.i686 0:3.5-0.5.20090913git.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package              Arch        Version                       Repository                                                                           Size================================================================================Installing: createrepo           noarch      0.9.9-18.el6                  base       94 kInstalling for dependencies: deltarpm             i686        3.5-0.5.20090913git.el6       base       73 k python-deltarpm      i686        3.5-0.5.20090913git.el6       base       27 kTransaction Summary================================================================================Install       3 Package(s)Total download size: 195 kInstalled size: 522 kIs this ok [y/N]: yDownloading Packages:(1/3): createrepo-0.9.9-18.el6.noarch.rpm                |  94 kB     00:00(2/3): deltarpm-3.5-0.5.20090913git.el6.i686.rpm         |  73 kB     00:00(3/3): python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm  |  27 kB     00:00--------------------------------------------------------------------------------Total                                            97 kB/s | 195 kB     00:02Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : deltarpm-3.5-0.5.20090913git.el6.i686                        1/3  Installing : python-deltarpm-3.5-0.5.20090913git.el6.i686                 2/3  Installing : createrepo-0.9.9-18.el6.noarch                               3/3  Verifying  : createrepo-0.9.9-18.el6.noarch                               1/3  Verifying  : python-deltarpm-3.5-0.5.20090913git.el6.i686                 2/3  Verifying  : deltarpm-3.5-0.5.20090913git.el6.i686                        3/3Installed:  createrepo.noarch 0:0.9.9-18.el6Dependency Installed:  deltarpm.i686 0:3.5-0.5.20090913git.el6  python-deltarpm.i686 0:3.5-0.5.20090913git.el6Complete!


        4) 创建索引文件 : createrepo /wuqinfei-yum-repo
        5) 在 "/etc/yum.repos.d"目录下 创建 "wuqinfei.repo"配置文件
            [wuqinfei]
            name = my repository
            baseurl = file:///wuqinfei-yum-repo/
        6) 清除缓存: yum clean all

0 0
原创粉丝点击