Yum使用

作者: 流芳不待人 | 来源:发表于2019-03-17 14:29 被阅读0次

    作为Linux中最常用命令之一,除了 install remove 以外 有必要了解下其他指令。

    搜索相关

    有时候list 比 search更好用

    list 其实并不是搜索,只是可以显示所有已经安装和可以安装的程序包,包括软件版本和归属的源。然而 search 似乎也应当是这个作用,偏偏list支持通配符,而search不支持。所以list更好用一些。

    yum list php*
    yum search php*
    

    通过命令找包名

    假如我们需要的某些命令服务器上没有。我们只知道命令,但不知道怎么安装。比如系统里没有ifconfig命令,但我们通过 yum list 找不到这个包。

    虽然有时候list比search更好用,但此处search另有妙用。

    [root@localhost ~]# yum search ifconfig
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * webtatic: uk.repo.webtatic.com
    ======================== Matched: ifconfig ========================
    knemo.x86_64 : A KDE network monitoring tool
    moreutils.x86_64 : Additional unix utilities
    net-tools.x86_64 : Basic networking tools
    python-psutil.x86_64 : A process and system utilities module for Python
    

    通过 yum search 我们可以找到支持这个命令的包。

    此外还可以通过执行 yum provides ifconfig 来查找。

    虽然直接查询只会得到如下反馈:

    You can use "/ifconfig" and/or "bin/ifconfig" to get that behaviour

    但经过提示,我们再使用 yum provides '*bin/ifconfig' 就可以看到 net-tools-1.60-114.el6.x86_64 提供这个命令

    [root@localhost ~]# yum provides '*bin/ifconfig'
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * webtatic: uk.repo.webtatic.com
    net-tools-1.60-114.el6.x86_64 : Basic networking tools
    Repo        : base
    Matched from:
    Filename    : /sbin/ifconfig
    

    源管理相关

    对源的操作可以直接修改 /etc/yum.repos.d/ 目录下的 .repo 文件。也可以使用 yum installyum remove 来操作。

    查看仓库源

    yum repolist
    
    yum repolist enabled # 显示所有启动的仓库
    yum repolist disabled # 显示所有禁用的仓库
    yum repolist all # 显示所有仓库
    

    指定源

    安装的时候可以指定某个源

    yum install XXX --enablerepo=ius
    

    启用和停用

    有时候我们的源里提供多个版本,比如mysql

    yum install https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm -y
    

    现在mysql已经有了8.0 因此这个源默认是mysql8.0。
    但是我们可以通过禁用80版本 然后指定mysql 5.6或5.7

    yum-config-manager --disable mysql80-community
    yum-config-manager --enable mysql57-community
    yum install --nogpgcheck -y mysql-community-server
    

    再比如 php。 remi 源提供了多个 php 版本,我们在安装前必须指定需要的版本。如果要更换版本,还需要停用之前的版本

    yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
    
    yum-config-manager --disable remi-php71 #停用7.1
    yum-config-manager --enable remi-php72 # 启用7.2
    

    缓存

    makecache

    yum makecache就是把服务器的包信息下载到本地电脑缓存起来。配合yum -C search xxx使用,不用上网检索就能查找软件信息

    清除缓存

    yum clean packages       #清除缓存目录下的软件包
    yum clean headers        #清除缓存目录下的 headers
    yum clean oldheaders     #清除缓存目录下旧的 headers
    
    yum clean all
    

    相关文章

      网友评论

          本文标题:Yum使用

          本文链接:https://www.haomeiwen.com/subject/vulumqtx.html