yum工具的使用


什么是yum工具

那么什么是yum呢?yum是yellowdog update manager的简称,它能够实现rpm管理的所有操作,并能够自动解决各rpm包之间的依赖关系。yum是rpm的前端工具,是基于rpm来实现软件的管理的一个工具。
你不能用yum去管理windows的exe程序包,也不能用yum去管理ubuntu的deb程序包,只能用yum来管理redhat系列的rpm包

yum的优劣势

yum有什么优势呢?yum最大的优势就是能够解决rpm的依赖问题,yum能够自动解决软件安装时的依赖关系。
当然了,有优势就有劣势,人无完人嘛,软件也是一样的,yum的缺陷就是如果在未完成安装的情况下强行中止安装过程,下次再安装时将无法解决依赖关系,Fedora22+、redhat7和centos7等可以通过手动安装dnf工具来解决此问题。
dnf是redhat7上用来代替yum的一个工具,其存在的意义就是处理yum的缺陷,但其用法与yum是完全一样的,甚至连选项都是一样的,你可以理解为dnf就是yum,只是换了个名字而已。所以说只要学会了yum就自然会dnf,大家不用担心学了yum又要去学dnf之类的问题

yum工具的使用

yum本地仓库

将光盘挂载到/mnt目录下

[root@YL ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@YL ~]# ls /mnt/	///mnt下的东西已经生成了
AppStream  EFI     isolinux  media.repo
BaseOS     images  LICENSE   TRANS.TBL

配置本地仓库

[root@YL ~]# cd /etc/yum.repos.d/	
[root@YL yum.repos.d]# ls
[root@YL yum.repos.d]# touch ly.repo
epel-modular.repo  epel-testing-modular.repo  ly.repo
epel.repo          epel-testing.repo
[root@YL yum.repos.d]# vi ly.repo 
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0

清理本地缓存

[root@YL yum.repos.d]# yum clean all
47 files removed

校验yum的本地仓库

[root@YL ~]# yum list all
zswap-cli.x86_64                       0.9.0-1.el8       epel     
zvbi.x86_64                            0.2.35-9.el8      epel     
zvbi-devel.x86_64                      0.2.35-9.el8      epel     
zvbi-fonts.noarch                      0.2.35-9.el8      epel     
zziplib.i686                           0.13.68-8.el8     AppStream
zziplib.x86_64                         0.13.68-8.el8     AppStream
zziplib-utils.x86_64                   0.13.68-8.el8     AppStrea

yum网络仓库

备份

[root@YL ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

在/etc/yum.repos.d/CentOS-Base.repo中只有包含又以下两个条件中的一个将会被删除

[root@YL yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

常用的command

列出仓库中已经有的,但是还没有安装的包

[root@YL ~]# yum list available |head 
Last metadata expiration check: 0:02:30 ago on Tue 12 Jul 2022 09:29:22 AM CST.
Available Packages
CUnit.i686                                             2.1.3-17.el8                                     AppStream
CUnit.x86_64                                           2.1.3-17.el8                                     AppStream
GConf2.i686                                            3.2.6-22.el8                                     AppStream
GConf2.x86_64                                          3.2.6-22.el8                                     AppStream
HdrHistogram.noarch                                    2.1.11-2.module_el8.2.0+460+6583c1d0             AppStream
HdrHistogram-javadoc.noarch                            2.1.11-2.module_el8.2.0+460+6583c1d0             AppStream
HdrHistogram_c.i686                                    0.9.13-2.el8                                     AppStream
HdrHistogram_c.x86_64                                  0.9.13-2.el8                                     AppStream

列出已经安装的包

[root@YL ~]# yum list installed | head
Installed Packages
NetworkManager.x86_64                         1:1.30.0-0.3.el8                      @anaconda    
NetworkManager-libnm.x86_64                   1:1.30.0-0.3.el8                      @anaconda    
NetworkManager-team.x86_64                    1:1.30.0-0.3.el8                      @anaconda    
NetworkManager-tui.x86_64                     1:1.30.0-0.3.el8                      @anaconda    
abattis-cantarell-fonts.noarch                0.0.25-4.el8                          @AppStream   
acl.x86_64                                    2.2.53-1.el8                          @anaconda    
adwaita-cursor-theme.noarch                   3.28.0-2.el8                          @anaconda    
adwaita-icon-theme.noarch                     3.28.0-2.el8                          @anaconda    
at-spi2-atk.x86_64                            2.26.2-1.el8                          @anaconda    

列出可用的升级包

[root@YL ~]# yum list updates
Last metadata expiration check: 0:04:23 ago on Tue 12 Jul 2022 09:29:22 AM CST.

清理缓存

[root@YL ~]# yum clean all
13 files removed

显示repo列表及其简要信息

[root@YL ~]# yum repolist all 
repo id                      repo name                     status
AppStream                    AppStream                     enabled
BaseOS                       BaseOS                        enabled

安装wget

[root@YL ~]# yum install wget
AppStream                         241 MB/s | 6.3 MB     00:00    
BaseOS                            231 MB/s | 2.4 MB     00:00    
Package wget-1.19.5-10.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

列出可升级的包

[root@YL ~]# yum list updates 
Last metadata expiration check: 0:02:40 ago on Tue 12 Jul 2022 09:37:17 AM CST.

删除wget

[root@YL ~]# yum remove wget.x86_64 
Dependencies resolved.
==================================================================
 Package   Arch        Version              Repository       Size
==================================================================
Removing:
 wget      x86_64      1.19.5-10.el8        @AppStream      2.8 M

Transaction Summary
==================================================================
Remove  1 Package

Freed space: 2.8 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                          1/1 
  Running scriptlet: wget-1.19.5-10.el8.x86_64                1/1 
  Erasing          : wget-1.19.5-10.el8.x86_64                1/1 
  Running scriptlet: wget-1.19.5-10.el8.x86_64                1/1 
  Verifying        : wget-1.19.5-10.el8.x86_64                1/1 
Installed products updated.

Removed:
  wget-1.19.5-10.el8.x86_64                                       

Complete!

显示ls包信息

[root@YL ~]# yum info  yum info ls
Last metadata expiration check: 0:04:32 ago on Tue 12 Jul 2022 09:37:17 AM CST.
Installed Packages
Name         : info
Version      : 6.5
Release      : 6.el8
Architecture : x86_64
Size         : 377 k
Source       : texinfo-6.5-6.el8.src.rpm
.......
URL          : https://github.com/rpm-software-management/dnf
License      : GPLv2+ and GPLv2 and GPL
Description  : Utility that allows users to manage packages on
             : their systems. It supports RPMs, modules and comps
             : groups & environments.

查看指定的文件或特性是由哪个包安装生成的

[root@YL ~]# yum whatprovides clear
Last metadata expiration check: 0:06:55 ago on Tue 12 Jul 2022 09:37:17 AM CST.
ncurses-6.1-7.20180224.el8.x86_64 : Ncurses support utilities
Repo        : @System
Matched from:
Filename    : /usr/bin/clear

ncurses-6.1-7.20180224.el8.x86_64 : Ncurses support utilities
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/clear

以指定的关键字搜索程序包名及summary信息

[root@YL ~]# yum search http
Last metadata expiration check: 0:07:34 ago on Tue 12 Jul 2022 09:37:17 AM CST.
================== Name & Summary Matched: http ==================
centos-logos-httpd.noarch : CentOS-related icons and pictures used
                          : by httpd
http-parser.i686 : HTTP request/response parser for C
http-parser.x86_64 : HTTP request/response parser for C

显示指定包的依赖关系

[root@YL ~]# yum deplist curl
Last metadata expiration check: 0:08:53 ago on Tue 12 Jul 2022 09:37:17 AM CST.
package: curl-7.61.1-17.el8.x86_64
  dependency: libc.so.6(GLIBC_2.17)(64bit)
   provider: glibc-2.28-141.el8.x86_64
  dependency: libcrypto.so.1.1()(64bit)
   provider: openssl-libs-1:1.1.1g-11.el8.x86_64
  dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit)
   provider: openssl-libs-1:1.1.1g-11.el8.x86_64
  dependency: libcurl(x86-64) >= 7.61.1-17.el8
   provider: libcurl-7.61.1-17.el8.x86_64
   provider: libcurl-minimal-7.61.1-17.el8.x86_64
  dependency: libcurl.so.4()(64bit)
   provider: libcurl-7.61.1-17.el8.x86_64
   provider: libcurl-minimal-7.61.1-17.el8.x86_64
  dependency: libmetalink.so.3()(64bit)
   provider: libmetalink-0.1.3-7.el8.x86_64
  dependency: libpthread.so.0()(64bit)
   provider: glibc-2.28-141.el8.x86_64
  dependency: libpthread.so.0(GLIBC_2.2.5)(64bit)
   provider: glibc-2.28-141.el8.x86_64
  dependency: libssl.so.1.1()(64bit)
   provider: openssl-libs-1:1.1.1g-11.el8.x86_64
  dependency: libz.so.1()(64bit)
   provider: zlib-1.2.11-17.el8.x86_64
  dependency: rtld(GNU_HASH)
   provider: glibc-2.28-141.el8.i686
   provider: glibc-2.28-141.el8.x86_64

查看dnf的历史事务信息

[root@YL ~]# dnf history 
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    10 | remove wget.x86_64       | 2022-07-12 09:40 | Removed        |    1   
     9 | -y install wget-1.19.5-1 | 2022-07-11 19:50 | Install        |    1  <
     8 | install -y htop          | 2022-07-07 09:41 | Install        |    1 > 
     7 | install -y https://mirro | 2022-07-07 09:39 | Install        |    1   
     6 | -y install psmisc        | 2022-07-06 15:11 | Install        |    1   
     5 | -y install zip           | 2022-07-02 17:40 | Install        |    2   
     4 | -y install bzip2         | 2022-07-02 17:27 | Install        |    1   
     3 | -y install bash-com*     | 2022-07-02 17:26 | Install        |    5   
     2 | -y install vim           | 2022-07-02 17:26 | Install        |    4   
     1 |                          | 2022-07-02 15:53 | Install        |  456 EE

安装本地rpm包,自动解决依赖关系

[root@YL ~]# dnf localinstall wget-1.14-18.el7_6.1.x86_64.rpm 
Last metadata expiration check: 0:21:53 ago on Tue 12 Jul 2022 09:37:17 AM CST.
Dependencies resolved.
==================================================================
 Package           Arch    Version            Repository     Size
==================================================================
Installing:
 wget              x86_64  1.14-18.el7_6.1    @commandline  547 k
Installing dependencies:
 compat-openssl10  x86_64  1:1.0.2o-3.el8     AppStream     1.1 M
 emacs-filesystem  noarch  1:26.1-5.el8       BaseOS         69 k
 libidn            x86_64  1.34-5.el8         AppStream     239 k
 make              x86_64  1:4.2.1-10.el8     BaseOS        498 k

Transaction Summary
==================================================================
Install  5 Packages

Total size: 2.5 M
Installed size: 7.2 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                          1/1 
  Installing       : make-1:4.2.1-10.el8.x86_64               1/5 
  Running scriptlet: make-1:4.2.1-10.el8.x86_64               1/5 
  Installing       : compat-openssl10-1:1.0.2o-3.el8.x86_64   2/5 
  Running scriptlet: compat-openssl10-1:1.0.2o-3.el8.x86_64   2/5 
  Installing       : emacs-filesystem-1:26.1-5.el8.noarch     3/5 
  Installing       : libidn-1.34-5.el8.x86_64                 4/5 
  Running scriptlet: libidn-1.34-5.el8.x86_64                 4/5 
  Installing       : wget-1.14-18.el7_6.1.x86_64              5/5 
  Running scriptlet: wget-1.14-18.el7_6.1.x86_64              5/5 
  Verifying        : compat-openssl10-1:1.0.2o-3.el8.x86_64   1/5 
  Verifying        : libidn-1.34-5.el8.x86_64                 2/5 
  Verifying        : emacs-filesystem-1:26.1-5.el8.noarch     3/5 
  Verifying        : make-1:4.2.1-10.el8.x86_64               4/5 
  Verifying        : wget-1.14-18.el7_6.1.x86_64              5/5 
Installed products updated.

Installed:
  compat-openssl10-1:1.0.2o-3.el8.x86_64                          
  emacs-filesystem-1:26.1-5.el8.noarch                            
  libidn-1.34-5.el8.x86_64                                        
  make-1:4.2.1-10.el8.x86_64                                      
  wget-1.14-18.el7_6.1.x86_64                                     

Complete!

列出可用的组

[root@YL ~]# yum grouplist 
Last metadata expiration check: 0:22:39 ago on Tue 12 Jul 2022 09:37:17 AM CST.
Available Environment Groups:
   Server with GUI
   Server
   Workstation
   Virtualization Host
   Custom Operating System
Installed Environment Groups:
   Minimal Install
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

安装一组软件

[root@YL ~]# yum groupinstall "system Tools"
Last metadata expiration check: 0:23:23 ago on Tue 12 Jul 2022 09:37:17 AM CST.
Dependencies resolved.
==================================================================
 Package                 Arch   Version           Repo       Size
==================================================================
Installing group/module packages:
 NetworkManager-libreswan
                         x86_64 1.2.10-4.el8      AppStream 120 k
 chrony                  x86_64 3.5-1.el8         BaseOS    271 k
 cifs-utils              x86_64 6.8-3.el8         BaseOS     96 k
.........
  timedatex-0.5-3.el8.x86_64                                      
  tmux-2.7-1.el8.x86_64                                           
  xdelta-3.1.0-4.el8.x86_64                                       
  zsh-5.5.1-6.el8_1.2.x86_64                                      
Complete!

创建yum仓库的元数据信息

[root@YL ~]# dnf -y install createrepo
Last metadata expiration check: 0:02:10 ago on Tue 12 Jul 2022 10:00:51 AM CST.
Dependencies resolved.
==================================================================
 Package             Arch     Version           Repository   Size
==================================================================
Installing:
 createrepo_c        x86_64   0.16.2-1.el8      AppStream    88 k
Installing dependencies:
 createrepo_c-libs   x86_64   0.16.2-1.el8      AppStream   113 k
 drpm                x86_64   0.4.1-3.el8       AppStream    68 k

Transaction Summary
==================================================================
Install  3 Packages

Total size: 269 k
Installed size: 577 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                          1/1 
  Installing       : drpm-0.4.1-3.el8.x86_64                  1/3 
  Installing       : createrepo_c-libs-0.16.2-1.el8.x86_64    2/3 
  Installing       : createrepo_c-0.16.2-1.el8.x86_64         3/3 
  Running scriptlet: createrepo_c-0.16.2-1.el8.x86_64         3/3 
  Verifying        : createrepo_c-0.16.2-1.el8.x86_64         1/3 
  Verifying        : createrepo_c-libs-0.16.2-1.el8.x86_64    2/3 
  Verifying        : drpm-0.4.1-3.el8.x86_64                  3/3 
Installed products updated.

Installed:
  createrepo_c-0.16.2-1.el8.x86_64                                
  createrepo_c-libs-0.16.2-1.el8.x86_64                           
  drpm-0.4.1-3.el8.x86_64                                         

Complete!

查询历史执行yum命令ID详细信息

[root@YL ~]# dnf history info 14
Transaction ID : 14
Begin time     : Tue 12 Jul 2022 10:08:33 AM CST
Begin rpmdb    : 538:4ef2fd4666b0ae3fa2376fef6f61a0194474dc7c
End time       : Tue 12 Jul 2022 10:08:33 AM CST (0 seconds)
End rpmdb      : 538:4ef2fd4666b0ae3fa2376fef6f61a0194474dc7c
User           : root <root>
Return-Code    : Success
Releasever     : 8
Command Line   : -y groups mark install Development Tools
Comment        : 
Packages Altered:
    Install @development 

标记安装

把这个组包标记成已安装。

[root@YL ~]# dnf -y groups mark install 'Development Tools'
Last metadata expiration check: 0:07:42 ago on Tue 12 Jul 2022 10:00:51 AM CST.
Dependencies resolved.
==================================================================
 Package        Architecture  Version        Repository      Size
==================================================================
Installing Groups:
 Development Tools
                                                                 

Transaction Summary
==================================================================

Complete!
posted @   Tqing  阅读(518)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示