• Linux教程 Yum命令的使用


    在这篇文章中,我们将学习如何安装,更新,删除,查找安装包,管理安装包以及安装包的仓库在Linux系统使用RedHat开发的YUM(Yellowdog Updater Modified)工具。以下这些命令例子主要使用的是CentOS 6.3 练习总结出来的,你也可以使用这些命令来对应的Linux环境上进行学习和练习。但是在使用这些命令时,你首先得熟悉Linux的命令,否则的话,有可能会操作失误,对系统造成一定的影响和损坏。

    什么是YUM?

    YUM (Yellowdog Updater Modified)  是一个开源的命令行工具,以及基于图形的软件包管理工具, 用于基于 RPM (RedHat Package Manager) 的 Linux 系统。它允许用户和系统管理员容易的安装,升级,卸载或者查找软件安装包在Linux系统中,它被开发以及发布通过 Seth Vidal 开源在GPL(General Public License) 下。这样的话任何人都可以下载和访问代码进行开发以及修复Bugs。YUM使用大量的第三方仓库通过依赖来自动安装包。

    1,使用YUM安装一个软件

    安装一个软件叫Firefox,仅仅运行以下命令,将会自动发现以及安装所有要求的依赖。

    # yum install firefox
    Loaded plugins: fastestmirror
    Dependencies Resolved
      ================================================================================================
    Package   Arch Version Repository Size
    ================================================================================================
    Updating:
    firefox i686 10.0.6-1.el6.centos updates 20 M
    Updating for dependencies:
    xulrunner i686 10.0.6-1.el6.centos updates 12 M
    Transaction Summary
    ================================================================================================
    Install 0 Package(s)
    Upgrade 2 Package(s)
    Total download size: 32 M
    Is this ok [y/N]: y
    Downloading Packages:
    (1/2): firefox-10.0.6-1.el6.centos.i686.rpm | 20 MB 01:10
    (2/2): xulrunner-10.0.6-1.el6.centos.i686.rpm | 12 MB 00:52
    ------------------------------------------------------------------------------------------------
    Total 63 kB/s | 32 MB 02:04
    Updated:
    firefox.i686 0:10.0.6-1.el6.centos
    Dependency Updated:
    xulrunner.i686 0:10.0.6-1.el6.centos
    Complete!

    以上命令安装任何包之前都会询问是否要安装,如果你想要自动安装没有任何提示,在命令里加一个参数-y 即可,例子如下:

    # yum -y install firefox

    2,使用YUM删除一个软件

    删除一个软件叫Firefox,仅仅运行以下命令,将会自动删除该软件的所有的依赖。

    # yum remove firefox
    Loaded plugins: fastestmirror
    Setting up Remove Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package firefox.i686 0:10.0.6-1.el6.centos set to be erased
    --> Finished Dependency Resolution
    Dependencies Resolved
    =================================================================================================
    Package Arch Version Repository Size
    =================================================================================================
    Removing:
    firefox i686 10.0.6-1.el6.centos @updates 23 M
    Transaction Summary
    =================================================================================================
    Remove 1 Package(s)
    Reinstall 0 Package(s)
    Downgrade 0 Package(s)
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Erasing : firefox-10.0.6-1.el6.centos.i686
    1/1
    Removed:
    firefox.i686 0:10.0.6-1.el6.centos
    Complete!

    相同的是以上命令执行还是会提醒你是否要卸载,如果不需要提示请加参数-y。

    # yum -y remove firefox

    3,使用YUM升级一个软件

    升级一个老版本的MySQL软件,仅仅运行以下命令,将会自动发现以及安装所有要求的依赖。

    # yum update mysql
    Loaded plugins: fastestmirror
    Dependencies Resolved
    =================================================================================================
    Package Arch Version Repository Size
    =================================================================================================
    Updating:
    vsftpd i386 2.0.5-24.el5_8.1 updates 144 k
    Transaction Summary
    =================================================================================================
    Install 0 Package(s)
    Upgrade 1 Package(s)
    Total size: 144 k
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Updating : vsftpd
    1/2
    Cleanup : vsftpd
    2/2
    Updated:
    vsftpd.i386 0:2.0.5-24.el5_8.1
    Complete!

    4,使用YUM列出一个软件的信息

    使用list函数通过安装包的名字查找软件,例如查找openssh使用以下命令

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

    如果要让你的查询更精确,使用那个安装的对应的版本进行查询。如下:

    # yum list openssh-4.3p2

    5,使用YUM查询匹配的软件

    如果你记不住软件的名称,可以使用search来查找匹配该名称的所有软件。

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

    6,使用YUM获取一个软件的信息

    安装一个软件前你想要知道该软件的信息,仅仅运行以下命令,将会得到该软件的信息。

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

    7,使用YUM列出所有有效的安装包

    使用YUM列出所有有效的安装包

    # yum list | less

    8,使用YUM列出所有已安装的软件包

    使用以下命令则列出所有已安装的软件安装包

    # yum list installed | less

    9,使用YUM查找对应的文件所属的安装包

    使用provide命令查找对应文件所属的软件安装包。就比如查找htppd.conf文件

    # yum provides /etc/httpd/conf/httpd.conf
    Loaded plugins: fastestmirror
    httpd-2.2.3-63.el5.centos.i386 : Apache HTTP Server
    Repo : base
    Matched from:
    Filename : /etc/httpd/conf/httpd.conf
    httpd-2.2.3-63.el5.centos.1.i386 : Apache HTTP Server
    Repo : updates
    Matched from:
    Filename : /etc/httpd/conf/httpd.conf
    httpd-2.2.3-65.el5.centos.i386 : Apache HTTP Server
    Repo : updates
    Matched from:
    Filename : /etc/httpd/conf/httpd.conf
    httpd-2.2.3-53.el5.centos.1.i386 : Apache HTTP Server
    Repo : installed
    Matched from:
    Other : Provides-match: /etc/httpd/conf/httpd.conf

    10,使用YUM检查可升级的软件安装包

    使用以下命令检查你的系统有多少软件包能够升级

    # yum check-update

    11,使用YUM升级系统

    使用以下命令将升级最新的系统软件版本。

    # yum update

    12,使用YUM列出能安装的一组包

    在Linux系统中,许多安装被绑定到到一个特定的组,从而不要单独对每一个安装包进行安装,你安装特定组的包,将安装所有相关联的包。例如使用以下命令显示有效的组。

    # yum grouplist
    Installed Groups:
    Administration Tools
    DNS Name Server
    Dialup Networking Support
    Editors
    Engineering and Scientific
    FTP Server
    Graphics
    Java Development
    Legacy Network Server
    Available Groups:
    Authoring and Publishing
    Base
    Beagle
    Cluster Storage
    Clustering
    Development Libraries
    Development Tools
    Eclipse
    Educational Software
    KDE (K Desktop Environment)
    KDE Software Development

    13,使用YUM安装一组安装包

    安装一组特定的软件安装包,我们使用命令groupinstall,例如安装软件MySqlDatabase,只需要执行以下命令。

    # yum groupinstall 'MySQL Database'
    Dependencies Resolved
    =================================================================================================
    Package Arch Version Repository Size
    =================================================================================================
    Updating:
    unixODBC i386 2.2.11-10.el5 base 290 k
    Installing for dependencies:
    unixODBC-libs i386 2.2.11-10.el5 base 551 k
    Transaction Summary
    =================================================================================================
    Install 1 Package(s)
    Upgrade 1 Package(s)
    Total size: 841 k
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Installing : unixODBC-libs 1/3
    Updating : unixODBC 2/3
    Cleanup : unixODBC 3/3
    Dependency Installed:
    unixODBC-libs.i386 0:2.2.11-10.el5
    Updated:
    unixODBC.i386 0:2.2.11-10.el5
    Complete!

    14,使用YUM升级一组软件包

    升级已经安装的一组软件包,使用以下命令即可安装。

    # yum groupupdate 'DNS Name Server'
    Dependencies Resolved
    =================================================================================================
    Package Arch Version Repository Size
    =================================================================================================
    Updating:
    bind i386 30:9.3.6-20.P1.el5_8.2 updates 981 k
    bind-chroot i386 30:9.3.6-20.P1.el5_8.2 updates 47 k
    Updating for dependencies:
    bind-libs i386 30:9.3.6-20.P1.el5_8.2 updates 864 k
    bind-utils i386 30:9.3.6-20.P1.el5_8.2 updates 174 k
    Transaction Summary
    =================================================================================================
    Install 0 Package(s)
    Upgrade 4 Package(s)
    Total size: 2.0 M
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Updating : bind-libs 1/8
    Updating : bind 2/8
    Updating : bind-chroot 3/8
    Updating : bind-utils 4/8
    Cleanup : bind 5/8
    Cleanup : bind-chroot 6/8
    Cleanup : bind-utils 7/8
    Cleanup : bind-libs 8/8
    Updated:
    bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2
    Dependency Updated:
    bind-libs.i386 30:9.3.6-20.P1.el5_8.2 bind-utils.i386 30:9.3.6-20.P1.el5_8.2
    Complete!

    15,使用YUM删除一组软件安装包

    删除系统中已存在的一组软件包,使用以下命令

    # yum groupremove 'DNS Name Server'
    Dependencies Resolved
    =================================================================================================
    Package Arch Version Repository Size
    =================================================================================================
    Removing:
    bind i386 30:9.3.6-20.P1.el5_8.2 installed 2.1 M
    bind-chroot i386 30:9.3.6-20.P1.el5_8.2 installed 0.0
    Transaction Summary
    =================================================================================================
    Remove 2 Package(s)
    Reinstall 0 Package(s)
    Downgrade 0 Package(s)
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Erasing : bind 1/2
    warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
    Erasing : bind-chroot 2/2
    Removed:
    bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2
    Complete!

    16,列出可使用的YUM仓库

    使用以下命令列出所有可使用的仓库的在你的系统。

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

    17,列出所有可用以及不可用的YUM仓库

    使用以下命令列出所有可使用的和不可使用的仓库的在你的系统。

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

    18,安装一个软件包从特定的仓库

    从一个特定的可用的或者不可用的仓库中安装一个软件安装包,你应该使用–enablerepo 参数来指定仓库,例如安装phpmyadmin安装包,你执行以下命令即可。

    # yum --enablerepo=epel install phpmyadmin

    Dependencies Resolved
    =============================================================================================
    Package Arch Version Repository Size
    =============================================================================================
    Installing:
    phpMyAdmin noarch 3.5.1-1.el6 epel 4.2 M
    Transaction Summary
    =============================================================================================
    Install 1 Package(s)
    Total download size: 4.2 M
    Installed size: 17 M
    Is this ok [y/N]: y
    Downloading Packages:
    phpMyAdmin-3.5.1-1.el6.noarch.rpm | 4.2 MB 00:25
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Installing : phpMyAdmin-3.5.1-1.el6.noarch 1/1
    Verifying : phpMyAdmin-3.5.1-1.el6.noarch 1/1

    Installed:
    phpMyAdmin.noarch 0:3.5.1-1.el6
    Complete!

    18,使用YUM Shell 进行交互

    YUM Shell能够执行多个命令的脚本。

    # yum shell
    Loaded plugins: fastestmirror
    Setting up Yum Shell
    > update httpd
    Loading mirror speeds from cached hostfile
    * base: mirrors.sin3.sg.voxel.net
    * epel: ftp.riken.jp
    * extras: mirrors.sin3.sg.voxel.net
    * updates: mirrors.sin3.sg.voxel.net
    Setting up Update Process
    >

    19,清除YUM缓存

    默认情况下YUM保持所有可用的安装包的仓库的数据在/var/cache/yum/ 目录下的每一个子目录中,清除所有的可用的仓库的缓存,你需要运行以下命令清除所有缓存并且确保没有空间被占用,一般情况下,我们是不建议清除的,因为我们想保留缓存在系统中,方便安装和查找。

    # yum clean all

    20,查看YUM的安装历史

    列出所有过去YUM处理的操作以及YUM安装的历史记录

    # yum history

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

    以上是所有练习归纳的YUM命令,如果你有任何其它相关的YUM的命令,可以在留言或者评论区留下你想要新增的YUM命令,后期更新到文章上,多谢大家的支持,写的不好的地方请多多包含,也望能提出你宝贵的意见。

  • 相关阅读:
    说一下 JSP 的 4 种作用域?
    CSS jquery 以动画方式显示投票结果图表
    Python动画【偶尔玩玩,挺好】
    关于Python【社区版】爬取网站图片
    Java 发送短信验证码【网建平台】
    Android发送接收短信
    如何在Java面试中介绍项目经验?
    Java面试之项目介绍
    IntelliJ IDEA 如何清理缓存和重启
    java实现支付宝接口-支付流程
  • 原文地址:https://www.cnblogs.com/Hackerman/p/10915238.html
Copyright © 2020-2023  润新知