使用yum安装和更新软件包

目标

  使用yum命令查找、安装和更新软件包

名词定义

  • 简介

  yum的设计目标是在管理基于RPM的软件安装和更新方面成为一个更理想的系统。yum命令允许安装、更新、删除和获取有关软件包以及其依赖项的信息。可以获取已执行事务的历史记录并使用多个红帽及第三方软件存储库。

实操演示

命令:yum

语法:yum 选项 参数
info:查询软件包详情
list: 列出已安装和可用的软件包
update:更新软件包
install:安装软件包
remove:删除软件包
search:查询软件包
provides:根据命令查询所属软件包
makecache:生成软件包缓存
group:使用软件包组进行管理

clean packages:清理缓存的软件包
clean headers:清除缓存目录下的 headers
clean oldheaders:清除缓存目录下旧的 headers
clean all:清除缓存目录下的软件包及旧的 headers

##查询软件包信息
[root@sinfotek src]# yum info yum
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
名称    :yum
架构    :noarch
版本    :3.4.3
发布    :163.el7.centos
大小    :5.6 M
源    :installed
来自源:anaconda
简介    : RPM package installer/updater/manager
网址    :http://yum.baseurl.org/
协议    : GPLv2+
描述    : Yum is a utility that can check for and automatically
         : download and install updated RPM packages. Dependencies
         : are obtained and downloaded automatically, prompting the
         : user for permission as necessary.

##查询该文件由那个软件包生成
[root@sinfotek src]# yum provides cat
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
extras/7/x86_64/filelists_db                  | 277 kB     00:00     
coreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used
                             : in shell scripts
源    :base
匹配来源:
文件名    :/bin/cat

##查询ftp软件包
[root@sinfotek src]# yum search ftp
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
========================= N/S matched: ftp ==========================
ftp.x86_64 : The standard UNIX FTP (File Transfer Protocol) client
lftp-scripts.noarch : Scripts for lftp
syslinux-tftpboot.noarch : SYSLINUX modules in /var/lib/tftpboot,
                         : available for network booting
tftp.x86_64 : The client for the Trivial File Transfer Protocol
            : (TFTP)
tftp-server.x86_64 : The server for the Trivial File Transfer
                   : Protocol (TFTP)
vsftpd.x86_64 : Very Secure Ftp Daemon
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
curl.x86_64 : A utility for getting files from remote servers (FTP,
            : HTTP, and others)
lftp.i686 : A sophisticated file transfer program
lftp.x86_64 : A sophisticated file transfer program
wget.x86_64 : A utility for retrieving files using the HTTP or FTP
            : protocols

  名称和简介匹配 only,使用“search all”试试。

##安装软件包
[root@sinfotek src]# yum install vsftpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
base                                          | 3.6 kB     00:00     
extras                                        | 2.9 kB     00:00     
updates                                       | 2.9 kB     00:00     
updates/7/x86_64/primary_db                     |  16 MB   00:16     
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-29.el7_9 将被 安装
--> 解决依赖关系完成

依赖关系解决

=====================================================================
 Package      架构         版本                  源             大小
=====================================================================
正在安装:
 vsftpd       x86_64       3.0.2-29.el7_9        updates       173 k

事务概要
=====================================================================
安装  1 软件包

总下载量:173 k
安装大小:353 k
Is this ok [y/d/N]: y
Downloading packages:
vsftpd-3.0.2-29.el7_9.x86_64.rpm                | 173 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : vsftpd-3.0.2-29.el7_9.x86_64                     1/1 
  验证中      : vsftpd-3.0.2-29.el7_9.x86_64                     1/1 

已安装:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                     

完毕!

##卸载软件包
[root@sinfotek src]# yum remove vsftpd
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-29.el7_9 将被 删除
--> 解决依赖关系完成

依赖关系解决

=====================================================================
 Package      架构         版本                 源              大小
=====================================================================
正在删除:
 vsftpd       x86_64       3.0.2-29.el7_9       @updates       353 k

事务概要
=====================================================================
移除  1 软件包

安装大小:353 k
是否继续?[y/N]:y   
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : vsftpd-3.0.2-29.el7_9.x86_64                     1/1 
  验证中      : vsftpd-3.0.2-29.el7_9.x86_64                     1/1 

删除:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                     

完毕!

##查看可用的软件包组安装
[root@sinfotek src]# yum groups list 
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成

##查询安装记录
[root@sinfotek src]# yum history 
已加载插件:fastestmirror, langpacks
ID     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
     6 | root <root>              | 2022-07-01 15:16 | Erase          |    1   
     5 | root <root>              | 2022-07-01 15:15 | Install        |    1  <
     4 | root <root>              | 2022-02-25 09:26 | I, U           |   69 > 
     3 | root <root>              | 2022-01-20 09:11 | Update         |    3 EE
     2 | root <root>              | 2022-01-17 09:53 | Update         |    2   
     1 | 系统 <空>                | 2022-01-16 17:55 | Install        | 1490   
history list























文档更新时间: 2022-07-01 15:22   作者:xiubao yan