• Linux学习-21-yum命令(查询、安装、升级和卸载软件包)和软件组管理


    7.9 Linux yum命令(查询、安装、升级和卸载软件包)
    • yum 提供了查找、安装、删除某一个、一组甚至全部软件包的命令

    • yum 语法

      yum [options] [command] [package ...]
      
      • 1
      • **options:**可选,选项包括-h(帮助),-y(当安装过程提示选择全部为 “yes”),-q(不显示安装的过程)等等。
      • **command:**要进行的操作。
      • **package:**安装的包名。
    7.9.1 yum查询命令
    • 使用 yum 对软件包执行查询操作,常用命令可分为以下几种:
    • yum list:查询所有已安装和可安装的软件包
    [root@CncLucZK yum.repos.d]# yum list
    #查询所有可用软件包列表
    Installed Packages
    #已经安装的软件包
    ConsdeKit.i686 0.4.1-3.el6
    @anaconda-CentOS-201207051201 J386/6.3
    ConsdeKit-libs.i686 0.4.1-3.el6 @anaconda-CentOS-201207051201 J386/6.3
    ……
    Available Packages
    #还可以安装的软件包
    389-ds-base.i686 1.2.10.2-15.el6 c6-media
    389-ds-base-devel.i686 1.2.10.2-15.el6 c6-media
    #软件名 版本 所在位置(光盘)
    ……
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • yum list 包名:查询执行软件包的安装情况。
    [root@CncLucZK etc]# yum list yum
    Repository epel is listed more than once in the configuration
    Installed Packages
    yum.noarch                         4.0.9.2-5.el8                          @anaconda
    Available Packages
    yum.noarch                         4.7.0-4.el8 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • yum search 关键字:从 yum 源服务器上查找与关键字相关的所有软件包。例如:
    [root@CncLucZK etc]# yum search redis
    Repository epel is listed more than once in the configuration
    =========================== Name Exactly Matched: redis ===========================
    redis.x86_64 : A persistent key-value database
    ========================== Summary & Name Matched: redis ==========================
    perl-Redis.noarch : Perl binding for Redis database
    hiredis-devel.x86_64 : Development files for hiredis
    syslog-ng-redis.x86_64 : Redis support for syslog-ng
    perl-RDF-Trine-redis.noarch : RDF::Trine store in Redis
    hiredis.x86_64 : Minimalistic C client library for Redis
    uwsgi-logger-redis.x86_64 : uWSGI - redislog logger plugin
    redis-doc.noarch : Documentation for Redis including man pages
    uwsgi-router-redis.x86_64 : uWSGI - Plugin for Redis router support
    pcp-pmda-redis.x86_64 : Performance Co-Pilot (PCP) metrics for Redis
    redis-devel.x86_64 : Development header for Redis module development
    python3-redis.noarch : Python 3 interface to the Redis key-value store
    perl-Apache-Session-Redis.noarch : Redis driver for Apache::Session::NoSQL
    ============================= Summary Matched: redis ==============================
    pdns-ixfrdist.x86_64 : A program to redistribute zones over AXFR and IXFR
    lpf.noarch : Local package factory - build non-redistributable rpms
    python3-django-rq.noarch : App that provides django integration for RQ (Redis
                             : Queue)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • yum info 包名:查询执行软件包的详细信息。例如:
    [root@CncLucZK etc]# yum info redis
    Repository epel is listed more than once in the configuration
    Available Packages			<-没有安装
    Name         : redis		<-包名
    Version      : 5.0.3		<-版本
    Release      : 5.module_el8.4.0+955+7126e393	<—发布版本
    Arch         : x86_64	<-适合的硬件平台
    Size         : 927 k	 <—大小
    Source       : redis-5.0.3-5.module_el8.4.0+955+7126e393.src.rpm
    Repo         : AppStream		<-仓库
    Summary      : A persistent key-value database
    URL          : http://redis.io
    License      : BSD and MIT
    Description  : Redis is an advanced key-value store. It is often referred to as a
                 : data structure server since keys can contain strings, hashes, lists,
                 : sets and sorted sets.
                 : 
                 : You can run atomic operations on these types, like appending to a
                 : string; incrementing the value in a hash; pushing to a list;
                 : computing set intersection, union and difference; or getting the
                 : member with highest ranking in a sorted set.
                 : 
                 : In order to achieve its outstanding performance, Redis works with an
                 : in-memory dataset. Depending on your use case, you can persist it
                 : either by dumping the dataset to disk every once in a while, or by
                 : appending each command to a log.
                 : 
                 : Redis also supports trivial-to-setup master-slave replication, with
                 : very fast non-blocking first synchronization, auto-reconnection on
                 : net split and so forth.
                 : 
                 : Other features include Transactions, Pub/Sub, Lua scripting, Keys
                 : with a limited time-to-live, and configuration settings to make
                 : Redis behave like a cache.
                 : 
                 : You can use Redis from most programming languages also.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    7.9.2 yum安装命令
    • yum 安装软件包的命令基本格式为:
    [root@CncLucZK yum.repos.d]# yum install 包名
    [root@CncLucZK yum.repos.d]# yum -y install 包名
    
    • 1
    • 2
    • 其中:

      • install:表示安装软件包。
      • -y:自动回答 yes。如果不加 -y,那么每个安装的软件都需要手工回答 yes;
    • 例如使用此 yum 命令安装 gcc:

    [root@CncLucZK yum jepos.d]#yum -y install gcc
    #使用yum自动安装gcc,会先检查软件的属性相依问题
    
    • 1
    • 2
    • gcc 是 C 语言的编译器,鉴于该软件包涉及到的依赖包较多,建议使用 yum 命令安装。

    对于 Linux 软件安装时提示缺失库的,可以使用 yum 的 provides 参数查看 redis的库文件包含在那个安装包中只需要执行以下命令,然后按查询到安装包包名,使用 yum install 安装即可。

    [root@CncLucZK ~]# yum provides redis
    Repository epel is listed more than once in the configuration
    Last metadata expiration check: 0:48:40 ago on Mon 17 Oct 2022 04:09:07 PM CST.
    redis-5.0.3-5.module_el8.4.0+955+7126e393.x86_64 : A persistent key-value database
    Repo        : AppStream
    Matched from:
    Provide    : redis = 5.0.3-5.module_el8.4.0+955+7126e393
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    7.9.3 yum 升级命令
    • 使用 yum 升级软件包,需确保 yum 源服务器中软件包的版本比本机安装的软件包版本高

    • yum 升级软件包常用命令如下:

      • yum check-update:列出所有可更新的软件清单命令
      • yum -y update/yum update:升级所有软件包。不过考虑到服务器强调稳定性,因此该命令并不常用。
      • yum -y update 包名/yum update 包名:升级特定的软件包。
    7.9.4 yum 卸载命令
    • 使用 yum 卸载软件包时,会同时卸载所有与该包有依赖关系的其他软件包,即便有依赖包属于系统运行必备文件,也会被 yum 无情卸载,带来的直接后果就是使系统崩溃。除非你能确定卸载此包以及它的所有依赖包不会对系统产生影响,否则不要使用 yum 卸载软件包。

    • yum 卸载命令的基本格式如下:

    [root@CncLucZK yum.repos.d]# yum remove 包名
    #卸载指定的软件包
    
    • 1
    • 2
    • 例如,使用 yum 卸载 redis软件包的命令如下:
    [root@CncLucZK yum.repos.d]# yum remove redis 	#卸载redis软件包
    #同样的,先解决属性相依的问题
    #若没有属性相依的问题,单纯移除一个软件
    
    • 1
    • 2
    • 3
    7.9.5 清除缓存命令:
    • yum clean packages: 清除缓存目录下的软件包
    • yum clean headers: 清除缓存目录下的 headers
    • yum clean oldheaders: 清除缓存目录下旧的 headers
    • yum clean, yum clean all (= yum clean packages; yum clean oldheaders) :清除缓存目录下的软件包及旧的 headers
    7.10 Linux yum管理软件组
    • 在安装 Linux 系统时,我们可以根据需要自定义安装软件包
      在这里插入图片描述
    • 选择“Customize now”,会进入图页面
      在这里插入图片描述
    • 上图所示为 Linux 列出的许多软件包组,例如编辑器、系统工具、开发工具等。在此页面,我们可以根据需要选择要安装的软件包。
    • 除了这样在系统安装过程中自选软件包组进行安装之外,当系统安装完成后,我们也可以通过 yum 命令来管理上图的这些软件包组。
    • yum 命令除了可以对软件包进行查询、安装、升级和卸载外,还可完成对软件包组的查询、安装和卸载操作。
    7.10.1 yum查询软件组包含的软件
    • 既然是软件包组,说明包含不只一个软件包,通过 yum 命令可以查询某软件包组中具体包含的软件包,命令格式如下:
    [root@CncLucZK ~]#yum groupinfo 软件组名
    #查询软件组中包含的软件
    
    • 1
    • 2
    • 可以用以下命令列出所有的软件包组
    [root@CncLucZK ~]# yum grouplist
    Repository epel is listed more than once in the configuration
    Last metadata expiration check: 0:01:13 ago on Thu 13 Oct 2022 05:25:38 PM CST.
    Available Environment Groups:
       Server with GUI
       Server
       Minimal Install
       Workstation
       KDE Plasma Workspaces
       Virtualization Host
       Custom Operating System
    Available Groups:
       Container Management
       .NET Core Development
       RPM Development Tools
       Development Tools
       Graphical Administration Tools
       Headless Management
       Legacy UNIX Compatibility
       Network Servers
       Scientific Support
       Security Tools
       Smart Card Support
       System Tools
       Fedora Packager
       Xfce
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 例如,查询 Server 软件包组中包含的软件包,可使用如下命令:
    [root@CncLucZK ~]# yum groupinfo Server
    Repository epel is listed more than once in the configuration
    Last metadata expiration check: 0:15:54 ago on Thu 13 Oct 2022 05:25:38 PM CST.
    Environment Group: Server
     Description: An integrated, easy-to-manage server.
     Mandatory Groups:
       Container Management
       Headless Management
       Server product core
       core
       hardware-support
       standard
     Optional Groups:
       Basic Web Server
       DNS Name Server
       Debugging Tools
       FTP Server
       File and Storage Server
       GNOME
       Guest Agents
       Hardware Monitoring Utilities
       Infiniband Support
       Mail Server
       Network File System Client
       Network Servers
       Performance Tools
       Remote Management for Linux
       Virtualization Hypervisor
       Windows File Server
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    7.10.2 yum安装软件组
    • 使用 yum 安装软件包组的命令格式如下:
    [root@CncLucZK ~]#yum groupinstall 软件组名
    #安装指定软件组,组名可以由grouplist查询出来
    
    • 1
    • 2
    • 例如,安装 Web Server 软件包组可使用如下命令:
    [root@CncLucZK ~]#yum groupinfo "System Tools“
    #安装系统工具
    
    • 1
    • 2
    7.10.3 yum命令卸载软件组
    • yum 卸载软件包组的命令格式如下:
    [root@CncLucZK ~]# yum groupremove 软件组名
    #卸载指定软件组
    
    • 1
    • 2
    • yum 软件包组管理命令更适合安装功能相对集中的软件包集合。例如,在初始安装 Linux 时没有安装图形界面,但后来发现需要图形界面的支持,这时可以手工安装图形界面软件组(X Window System 和 Desktop),就可以使用图形界面了。

    参考文献:
    Linux yum命令详解
    Linux yum 命令

    下一篇:Linux学习-22-源码包安装、卸载和升级
  • 相关阅读:
    【分布式】入门级NCCL多机并行实践 - 02
    Kubernetes Service对象
    Prometheus-v2控制子模块教学例程demo演示
    数据集:机器人理解世界的关键
    NDK20b FFmpeg4.2.2 编译和集成
    电影售票系统
    yolov5 v7.0自动标注
    云链商城连锁门店新零售O20系统以零售商城
    postman---postman参数化
    【论文|复现]Vertebra-Focused Landmark Detection For Scoliosis Assessment
  • 原文地址:https://blog.csdn.net/weixin_42045639/article/details/127680082