zoukankan      html  css  js  c++  java
  • 用于软件包管理的21个Linux YUM命令 转载

    http://flycars001.iteye.com/blog/1949085

    YUM到底是啥东东?

    YUM(Yellowdog Updater Modified)是一款开源命令行及图形化软件包管理工具,面向基于RPM(红帽软件包管理器)的Linux系统。 它让广大用户和系统管理员可以在系统上轻松地安装、更新、移除或搜索软件包。它由Seth Vidal开发和发布,采用了GPL(通用公共许可证),是一款开源工具。这意味着,谁都可以下载和访问代码,以修复软件错误,开发定制的软件包。YUM 通过解决软件包的依赖项问题,使用众多的第三方软件库来自动安装软件包。

    1. 使用Yum安装软件包

    想安装一个名为Firefox 14的软件包,只要运行下面这个命令,它会自动寻找并安装Firefox浏览器的所有必要依赖项。

    1. # yum install firefox 
    2. Loaded plugins: fastestmirror 
    3. Dependencies Resolved 
    4. ==================================== Package                    Arch        Version                    Repository            Size 
    5. ====================================
    6. Updating: 
    7. firefox                        i686        10.0.6-1.el6.centos     updates             20 M 
    8. Updating for dependencies: 
    9. xulrunner                     i686        10.0.6-1.el6.centos     updates             12 M 
    10. Transaction Summary 
    11. ===========================================Install       0 Package(s) 
    12. Upgrade       2 Package(s) 
    13. Total download size: 32 M 
    14. Is this ok [y/N]: y 
    15. Downloading Packages: 
    16. (1/2): firefox-10.0.6-1.el6.centos.i686.rpm                                |  20 MB   01:10 
    17. (2/2): xulrunner-10.0.6-1.el6.centos.i686.rpm                              |  12 MB   00:52 
    18. ------------------------------------------------------------------------------------------------ 
    19. Total                                                           63 kB/s |  32 MB   02:04 
    20. Updated: 
    21. firefox.i686 0:10.0.6-1.el6.centos 
    22. Dependency Updated: 
    23. xulrunner.i686 0:10.0.6-1.el6.centos 
    24. Complete! 

    上述命令会先要求予以确认,然后再将任何软件包安装到你的系统上。如果你不要求任何确认,就想自动安装软件包,可使用选项-y,如下例所示。

    1. # yum -y install firefox 

    2. 使用Yum移除软件包

    想完全移除软件包连同所有依赖项,只要运行下面这个命令,如下所示。

    1. # yum remove firefox 
    2. Loaded plugins: fastestmirror 
    3. Setting up Remove Process 
    4. Resolving Dependencies 
    5. --> Running transaction check 
    6. ---> Package firefox.i686 0:10.0.6-1.el6.centos set to be erased 
    7. --> Finished Dependency Resolution 
    8. Dependencies Resolved 
    9. ===========================================Package                    Arch        Version                        Repository            Size 
    10. ===========================================Removing: 
    11. firefox                    i686        10.0.6-1.el6.centos            @updates              23 M 
    12. Transaction  Summary 
    13. ===========================================
    14. Remove       1 Package(s) 
    15. Reinstall      0 Package(s) 
    16. Downgrade     0 Package(s) 
    17. Is this ok [y/N]: y 
    18. Downloading Packages: 
    19. Running rpm_check_debug 
    20. Running Transaction Test 
    21. Transaction Test Succeeded 
    22. Running Transaction 
    23. Erasing:firefox-10.0.6-1.el6.centos.i686                                   1/1 
    24. Removed: 
    25. firefox.i686 0:10.0.6-1.el6.centos 
    26. Complete! 

    同样,上述命令会先要求予以确认,然后再移除软件包。想禁用确认提示,只要添加选项-y,如下所示。

    1. # yum -y remove firefox 

    3. 使用Yum更新软件包

    假设你有过时版本的MySQL软件包,想把它更新到最新的稳定版本。只要运行下面这个命令,它就会自动解决所有的依赖项问题,并安装依赖项。

    1. # yum update mysql 
    2. Loaded plugins: fastestmirror 
    3. Dependencies Resolved 
    4. ===========================================Package            Arch                Version            Repository         Size 
    5. ===========================================Updating: 
    6. vsftpd             i386          2.0.5-24.el5_8.1           updates               144 k 
    7. Transaction  Summary 
    8. Install       0 Package(s) 
    9. Upgrade     1 Package(s) 
    10. Total size: 144 k 
    11. Is this ok [y/N]: y 
    12. Downloading Packages: 
    13. Running rpm_check_debug 
    14. Running Transaction Test 
    15. Finished Transaction Test 
    16. Transaction Test Succeeded 
    17. Running Transaction 
    18. Updating       : vsftpd                                  1/2 
    19. Cleanup        : vsftpd                                  2/2 
    20. Updated: 
    21. vsftpd.i386 0:2.0.5-24.el5_8.1 
    22. Complete! 

    4. 使用Yum列出软件包

    使用list函数,可搜索带名称的特定软件包。比如说,想搜索一个名为openssh的软件包,使用该命令。

    1. # yum list openssh 
    2. Loaded plugins: fastestmirror 
    3. Loading mirror speeds from cached hostfile 
    4. * base: mirror.neu.edu.cn 
    5. * epel: mirror.neu.edu.cn 
    6. * extras: mirror.neu.edu.cn 
    7. * rpmforge: mirror.nl.leaseweb.net 
    8. * updates: mirror.nus.edu.sg 
    9. Installed Packages 
    10. openssh.i386    4.3p2-72.el5_6.3                           installed 
    11. Available Packages   4.3p2-82.el5                          base 

    想让你的搜索更精确,明确软件包名称的版本,如果你知道的话。比如说,想搜索软件包的特定版本openssh-4.3p2 ,使用该命令。

    1. # yum list openssh-4.3p2 

    5. 使用Yum搜索软件包

    要是你不记得软件包的确切名称,那么可以使用search函数,搜索与指定软件包的名称相匹配的所有可用软件包。比如说,想搜索与vsftpd这个单词匹配的所有软件包。

    1. # yum search vsftpd 
    2. Loaded plugins: fastestmirror 
    3. Loading mirror speeds from cached hostfile 
    4. * base: mirror.neu.edu.cn 
    5. * epel: mirror.neu.edu.cn 
    6. * extras: mirror.neu.edu.cn 
    7. * rpmforge: mirror.nl.leaseweb.net 
    8. * updates: ftp.iitm.ac.in 
    9. ============================== Matched: vsftpd ======================== 
    10. ccze.i386 : A robust log colorizer 
    11. pure-ftpd-selinux.i386 : SELinux support for Pure-FTPD 
    12. vsftpd.i386 : vsftpd - Very Secure Ftp Daemon 

    6. 使用Yum获取软件包信息

    假设你想在安装软件包之前先知道它的信息。想获得某软件包的信息,只要执行下面这个命令。

    1. # yum info firefox 
    2. Loaded plugins: fastestmirror 
    3. Loading mirror speeds from cached hostfile 
    4. * base: mirror.neu.edu.cn 
    5. * epel: mirror.neu.edu.cn 
    6. * extras: mirror.neu.edu.cn 
    7. * rpmforge: mirror.nl.leaseweb.net 
    8. * updates: ftp.iitm.ac.in 
    9. Available Packages 
    10. Name      : firefox 
    11. Arch       : i386 
    12. Version     : 10.0.6 
    13. Release     : 1.el5.centos 
    14. Size        : 20 M 
    15. Repo       : updates 
    16. Summary    : Mozilla Firefox Web browser 
    17. URL       : http://www.mozilla.org/projects/firefox/ 
    18. License     : MPLv1.1 or GPLv2+ or LGPLv2+ 
    19. Description  : Mozilla Firefox is an open-source web browser, designed for standards 
    20. : compliance, performance and portability. 

    7. 使用Yum列出所有的可用软件包

    想列出Yum数据库中所有的可用软件包,使用下面这个命令。

    1. # yum list | less 

    8. 使用Yum列出所有的已安装软件包

    想列出系统上所有的已安装软件包,只要执行下面这个命令,它会显示所有的已安装软件包。

    1. # yum list installed | less 

    9. Yum Provides函数

    Yum provides函数用于查找某个特定文件属于哪个软件包。比如说,如果你想知道含有/etc/httpd/conf/httpd.conf文件的软件包的名称。

    1. # yum provides /etc/httpd/conf/httpd.conf 
    2. Loaded plugins: fastestmirror 
    3. httpd-2.2.3-63.el5.centos.i386 : Apache HTTP Server 
    4. Repo        : base 
    5. Matched from: 
    6. Filename    : /etc/httpd/conf/httpd.conf 
    7. httpd-2.2.3-63.el5.centos.1.i386 : Apache HTTP Server 
    8. Repo        : updates 
    9. Matched from: 
    10. Filename    : /etc/httpd/conf/httpd.conf 
    11. httpd-2.2.3-65.el5.centos.i386 : Apache HTTP Server 
    12. Repo        : updates 
    13. Matched from: 
    14. Filename    : /etc/httpd/conf/httpd.conf 
    15. httpd-2.2.3-53.el5.centos.1.i386 : Apache HTTP Server 
    16. Repo        : installed 
    17. Matched from: 
    18. Other       : Provides-match: /etc/httpd/conf/httpd.conf 

    10. 使用Yum检查可用更新版

    想找出你系统上有多少已安装软件包有可用更新版,只要使用下面这个命令。

    1. # yum check-update 

    11. 使用Yum更新系统

    想确保系统版本最新,打上了所有的安全补丁和二进制软件包更新,只要运行下面这个命令。它会为你的系统安装所有最新的补丁和安全更新版。

    1. # yum update 

    12. 列出所有的可用群组软件包

    在Linux中,软件包数量与特定群组捆绑在一起。你可以安装某个群组,它就会安装属于该群组的所有相关软件包,用不着使用Yum安装单个软件包。比如说,想列出所有的可用群组,只要执行下面这个命令。

    1. # yum grouplist 
    2. Installed Groups: 
    3. Administration Tools 
    4. DNS Name Server 
    5. Dialup Networking Support 
    6. Editors 
    7. Engineering and Scientific 
    8. FTP Server 
    9. Graphics 
    10. Java Development 
    11. Legacy Network Server 
    12. Available Groups: 
    13. Authoring and Publishing 
    14. Base 
    15. Beagle 
    16. Cluster Storage 
    17. Clustering 
    18. Development Libraries 
    19. Development Tools 
    20. Eclipse 
    21. Educational Software 
    22. KDE (K Desktop Environment) 
    23. KDE Software Development 

    13. 安装群组软件包

    想安装某个软件包群组,我们使用选项groupinstall。比如说,想安装"MySQL Database",只要执行下面这个命令。

    1. # yum groupinstall 'MySQL Database' 
    2. Dependencies Resolved 
    3. ==================================================================Package    Arch      Version   Repository        Size 
    4. ==================================================================Updating: 
    5. unixODBC                           i386      2.2.11-10.el5      base              290 k 
    6. Installing for dependencies: 
    7. unixODBC-libs                      i386      2.2.11-10.el5      base              551 k 
    8. Transaction Summary 
    9. ==================================================================Install       1 Package(s) 
    10. Upgrade       1 Package(s) 
    11. Total size: 841 k 
    12. Is this ok [y/N]: y 
    13. Downloading Packages: 
    14. Running rpm_check_debug 
    15. Running Transaction Test 
    16. Finished Transaction Test 
    17. Transaction Test Succeeded 
    18. Running Transaction 
    19. Installing     : unixODBC-libs  1/3 
    20. Updating       : unixODBC         2/3 
    21. Cleanup        : unixODBC         3/3 
    22. Dependency Installed: 
    23. unixODBC-libs.i386 0:2.2.11-10.el5 
    24. Updated: 
    25. unixODBC.i386 0:2.2.11-10.el5 
    26. Complete! 

    14. 更新群组软件包

    想更新任何现有的已安装群组软件包,只要运行下面这个命令,如下所示。

    1. # yum groupupdate 'DNS Name Server' 
    2. Dependencies Resolved 
    3. ==================================================================Package    Arch           Version  Repository           Size 
    4. ================================================================== 
    5. Updating: 
    6. bind                           i386            30:9.3.6-20.P1.el5_8.2          updates              981 k 
    7. bind-chroot                    i386            30:9.3.6-20.P1.el5_8.2          updates              47 k 
    8. Updating for dependencies: 
    9. bind-libs                      i386            30:9.3.6-20.P1.el5_8.2          updates              864 k 
    10. bind-utils                     i386            30:9.3.6-20.P1.el5_8.2          updates              174 k 
    11. Transaction Summary 
    12. Install       0 Package(s) 
    13. Upgrade       4 Package(s) 
    14. Total size: 2.0 M 
    15. Is this ok [y/N]: y 
    16. Downloading Packages: 
    17. Running rpm_check_debug 
    18. Running Transaction Test 
    19. Finished Transaction Test 
    20. Transaction Test Succeeded 
    21. Running Transaction 
    22. Updating       : bind-libs            1/8 
    23. Updating       : bind                 2/8 
    24. Updating       : bind-chroot          3/8 
    25. Updating       : bind-utils           4/8 
    26. Cleanup        : bind                 5/8 
    27. Cleanup        : bind-chroot          6/8 
    28. Cleanup        : bind-utils           7/8 
    29. Cleanup        : bind-libs            8/8 
    30. Updated: 
    31. bind.i386 30:9.3.6-20.P1.el5_8.2                  bind-chroot.i386 30:9.3.6-20.P1.el5_8.2 
    32. Dependency Updated: 
    33. bind-libs.i386 30:9.3.6-20.P1.el5_8.2             bind-utils.i386 30:9.3.6-20.P1.el5_8.2 
    34. Complete! 

    15. 移除群组软件包

    想从系统删除或移除任何现有的已安装群组软件包,只要使用下面这个命令。

    1. # yum groupremove 'DNS Name Server' 
    2. Dependencies Resolved 
    3. ==========================================Package                Arch              Version                         Repository          Size 
    4. ==========================================Removing: 
    5. bind                   i386              30:9.3.6-20.P1.el5_8.2         installed           2.1 M 
    6. bind-chroot            i386              30:9.3.6-20.P1.el5_8.2         installed           0.0 
    7. Transaction Summary 
    8. ==========================================Remove        2 Package(s) 
    9. Reinstall     0 Package(s) 
    10. Downgrade     0 Package(s) 
    11. Is this ok [y/N]: y 
    12. Downloading Packages: 
    13. Running rpm_check_debug 
    14. Running Transaction Test 
    15. Finished Transaction Test 
    16. Transaction Test Succeeded 
    17. Running Transaction 
    18. Erasing        : bind                                                   1/2 
    19. warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave 
    20. Erasing        : bind-chroot                                            2/2 
    21. Removed: 
    22. bind.i386 30:9.3.6-20.P1.el5_8.2                                        bind-chroot.i386 30:9.3.6-20.P1.el5_8.2 
    23. Complete! 

    16. 列出启用的Yum软件库

    列出系统里面所有启用的Yum软件库,使用下面这个选项。

    1. # yum repolist 
    2. repo id                     repo name                                            status 
    3. base                       CentOS-5 - Base                                      enabled:  2,725 
    4. epel                       Extra Packages for Enterprise Linux 5 - i386           enabled:  5,783 
    5. extras                      CentOS-5 - Extras                                      enabled:    282 
    6. mod-pagespeed              mod-pagespeed                                        enabled:      1 
    7. rpmforge                   RHEL 5 - RPMforge.net - dag                             enabled: 11,290 
    8. updates                    CentOS-5 - Updates                                     enabled:    743 
    9. repolist: 20,824 

    17. 列出所有启用和禁用的Yum软件库

    下面这个命令会显示系统上所有启用和禁用的yum软件库。

    1. # yum repolist all 
    2. repo id                     repo name                                            status 
    3. C5.0-base                   CentOS-5.0 - Base                                     disabled 
    4. C5.0-centosplus              CentOS-5.0 - Plus                                      disabled 
    5. C5.0-extras                  CentOS-5.0 - Extras                                    disabled 
    6. base                        CentOS-5 - Base                                      enabled:  2,725 
    7. epel                        Extra Packages for Enterprise Linux 5 - i386                enabled:  5,783 
    8. extras                      CentOS-5 - Extras                                      enabled:    282 
    9. repolist: 20,824 

    18. 安装来自特定软件库的软件包

    想安装来自某个启用或禁用的软件库的某个软件包,必须在yum命令中使用-enablerepo选项。比如,想安装PhpMyAdmin 3.5.2软件包,只要执行这个命令。

    1. # yum --enablerepo=epel install phpmyadmin 
    2. Dependencies Resolved 
    3. ================================================================== Package                Arch           Version            Repository           Size 
    4. ==================================================================Installing: 
    5. phpMyAdmin             noarch         3.5.1-1.el6        epel                 4.2 M 
    6. Transaction Summary 
    7. ==================================================================Install       1 Package(s) 
    8. Total download size: 4.2 M 
    9. Installed size: 17 M 
    10. Is this ok [y/N]: y 
    11. Downloading Packages: 
    12. phpMyAdmin-3.5.1-1.el6.noarch.rpm                       | 4.2 MB     00:25 
    13. Running rpm_check_debug 
    14. Running Transaction Test 
    15. Transaction Test Succeeded 
    16. Running Transaction 
    17. Installing : phpMyAdmin-3.5.1-1.el6.noarch             1/1 
    18. Verifying  : phpMyAdmin-3.5.1-1.el6.noarch             1/1 
    19. Installed: 
    20. phpMyAdmin.noarch 0:3.5.1-1.el6 
    21. Complete! 

    19. 交互式Yum外壳

    Yum实用工具提供了一个自定义外壳,你可以在这个环境下执行多个命令。

    1. # yum shell 
    2. Loaded plugins: fastestmirror 
    3. Setting up Yum Shell 
    4. > update httpd 
    5. Loading mirror speeds from cached hostfile 
    6. * base: mirrors.sin3.sg.voxel.net 
    7. * epel: ftp.riken.jp 
    8. * extras: mirrors.sin3.sg.voxel.net 
    9. * updates: mirrors.sin3.sg.voxel.net 
    10. Setting up Update Process 
    11. > 

    20. 清理Yum缓存内容

    默 认情况下,yum将所有软件库中启用软件包的数据,连同每个子目录保存在/var/cache/yum/中,想清除启用软件库中的所有缓存文件,你要定期 运行下面这个命令,清理所有缓存内容,并确保没有任何东西在使用不必要的存储空间。我们不想给出下面这个命令的输出结果,因为我们想保持缓存数据的原来样 子。

    1. # yum clean all 

    21. 查看Yum的历史记录

    想查看Yum命令的所有过去的事务,只要使用下面这个命令。

    1. # yum history 
    2. Loaded plugins: fastestmirror 
    3. ID     | Login user               | Date and time    | Action(s)      | Altered 
    4. ------------------------------------------------------------------ 
    5. 10 | root               | 2012-08-11 15:19 | Install        |    3 
    6. 9 | root               | 2012-08-11 15:11 | Install        |    1 
    7. 8 | root               | 2012-08-11 15:10 | Erase          |    1 EE 
    8. 7 | root               | 2012-08-10 17:44 | Install        |    1 
    9. 6 | root               | 2012-08-10 12:19 | Install        |    2 
    10. 5 | root               | 2012-08-10 12:14 | Install        |    3 
    11. 4 | root               | 2012-08-10 12:12 | I, U           |   13 E< 
    12. 3 | root               | 2012-08-09 13:01 | Install        |    1 > 
    13. 2 | root               | 2012-08-08 20:13 | I, U           |  292 EE 
    14. 1 | System            | 2012-08-08 17:15 | Install        |  560 
    15. history list 

    我们试图探讨所有基本面,给出了每个Yum命令的示例。要是遗漏了与Yum命令有关的任何内容,请在此留言告知我们,以便我们根据收到的反馈,不断更新内容。

  • 相关阅读:
    Java入门总结
    Java安装JDK
    ExcelPackage 读取、导出excel
    An error occurred while starting the application.
    EF core2.1+MySQL报错'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder..ctor(Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)
    数据表转换类
    The requested URL /xxxx.html was not found on this server
    .htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
    B2B多商铺初期权限数据库设计
    数据库持久化比较
  • 原文地址:https://www.cnblogs.com/davidwang456/p/3346963.html
Copyright © 2011-2022 走看看