暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

Linux中YUM的查询/安装/升级与删除功能

watson 2025-03-01
33

【导读】


    yum,是Yellow dog Updater Modified的简称,起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(yellow dog updater),后经杜克大学的Linux@Duke开发团队进行改进,遂有此名。


【目录】


一 yum的选项与参数介绍

二 测试用例


一 yum的选项与参数介绍

clean          Remove cached datamakecache      Generate the metadata cachesearch         Search package details for the given stringlist           List a package or groups of packagesinfo           Display details about a package or group of packagesprovides       Find what package provides the given value-y, --assumeyes       answer yes for all questions--downloadonly        don't update, just download
复制

    

二 测试用例


2.1 search查找某个软件名

[root@centos ~]# yum search raid Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile============================================================================= N/S matched: raid =============================================================================dmraid.x86_64 : dmraid (Device-mapper RAID tool and library)libblockdev-mdraid.x86_64 : The MD RAID plugin for the libblockdev librarydmraid-events.x86_64 : dmevent_tool (Device-mapper event tool) and DSOiprutils.x86_64 : Utilities for the IBM Power Linux RAID adaptersmdadm.x86_64 : The mdadm program controls Linux md devices (software RAID arrays)
  Name and summary matches only, use "search all" for everything.
复制

    注意:冒号(:)左边的是软件名称,右边的是在RPM内的name设置软件名

2.2 info展示软件包信息

[root@centos ~]# yum info raidLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileError: No matching Packages to list[root@centos ~]# yum info mdadmLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileInstalled PackagesName        : mdadmArch        : x86_64Version     : 4.0Release     : 13.el7Size        : 1.0 MRepo        : installedFrom repo   : anacondaSummary     : The mdadm program controls Linux md devices (software RAID arrays)URL         : http://www.kernel.org/pub/linux/utils/raid/mdadm/License     : GPLv2+Description : The mdadm program is used to create, manage, and monitor Linux MD (software            : RAID) devices.  As such, it provides similar functionality to the raidtools            : package.  However, mdadm is a single program, and it can perform            : almost all functions without a configuration file, though a configuration            : file can be used to help with some common tasks.
复制

2.3 list展示已经安装的软件

[root@centos ~]# yum list | head Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileInstalled PackagesGConf2.x86_64                           3.2.6-8.el7                    @anacondaGeoIP.x86_64                            1.5.0-11.el7                   @anacondaModemManager.x86_64                     1.6.10-1.el7                   @anacondaModemManager-glib.x86_64                1.6.10-1.el7                   @anacondaNetworkManager.x86_64                   1:1.10.2-13.el7                @anacondaNetworkManager-adsl.x86_64              1:1.10.2-13.el7                @anacondaNetworkManager-glib.x86_64              1:1.10.2-13.el7                @anaconda

Exiting on Broken Pipe
复制

2.4 updates列出系统上可升级的软件

[root@centos ~]# yum list updatesLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile
复制

2.5 provides查询命令是哪款软件提供的

[root@centos ~]# yum provides passwdLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfilepasswd-0.79-4.el7.x86_64 : An utility for setting or changing passwords using PAMRepo        : @anaconda[root@centos ~]# yum provides rsyncLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfilersync-3.1.2-4.el7.x86_64 : A program for synchronizing files over a networkRepo        : @anaconda
复制

2.6 下载yum配置文

[root@centos ~]# cd /etc/yum.repos.d/[root@centos yum.repos.d]# wget -O ./CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo--2024-08-26 23:31:56--  http://mirrors.aliyun.com/repo/Centos-7.repoResolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.46.149.240, 112.46.177.209, 112.46.177.207, ...Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.46.149.240|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 2523 (2.5K) [application/octet-stream]Saving to: ‘./CentOS-Base.repo’
100%[===================================================================================================================================>] 2,523 --.-K/s in 0s
2024-08-26 23:31:56 (273 MB/s) - ‘./CentOS-Base.repo’ saved [2523/2523]
复制

2.7 列出已经配置的所有可用仓库

[root@centos yum.repos.d]# yum repolist -v Loading "fastestmirror" pluginLoading "langpacks" pluginAdding en_US.UTF-8 to language listConfig time: 0.020Yum version: 3.4.3Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comSetting up Package Sackspkgsack time: 0.039Repo-id      : base/7/x86_64Repo-name    : CentOS-7 - Base - mirrors.aliyun.comRepo-revision: 1604001756Repo-updated : Fri Oct 30 04:03:00 2020Repo-pkgs    : 10,072Repo-size    : 8.9 GRepo-baseurl : http://mirrors.aliyun.com/centos/7/os/x86_64/, http://mirrors.aliyuncs.com/centos/7/os/x86_64/, http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Repo-expire  : 21,600 second(s) (last: Tue May 21 00:59:33 2024)  Filter     : read-only:presentRepo-filename: /etc/yum.repos.d/CentOS-Base.repo
Repo-id : extras/7/x86_64Repo-name : CentOS-7 - Extras - mirrors.aliyun.comRepo-revision: 1712079707Repo-updated : Wed Apr 3 01:41:49 2024Repo-pkgs : 526Repo-size : 1.0 GRepo-baseurl : http://mirrors.aliyun.com/centos/7/extras/x86_64/, http://mirrors.aliyuncs.com/centos/7/extras/x86_64/, : http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/Repo-expire : 21,600 second(s) (last: Tue May 21 00:59:33 2024) Filter : read-only:presentRepo-filename: /etc/yum.repos.d/CentOS-Base.repo
Repo-id : updates/7/x86_64Repo-name : CentOS-7 - Updates - mirrors.aliyun.comRepo-revision: 1715095692Repo-updated : Tue May 7 23:29:50 2024Repo-pkgs : 5,886Repo-size : 46 GRepo-baseurl : http://mirrors.aliyun.com/centos/7/updates/x86_64/, http://mirrors.aliyuncs.com/centos/7/updates/x86_64/, : http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/Repo-expire : 21,600 second(s) (last: Tue May 21 00:59:33 2024) Filter : read-only:presentRepo-filename: /etc/yum.repos.d/CentOS-Base.repo
repolist: 16,484
复制

2.8 清除暂存中旧的rpm头文件和包文件 && 重新生成缓存

[root@centos yum.repos.d]# yum clean all && yum makecache
复制

2.9 install安装软件包pam-devel

[root@centos yum.repos.d]# yum install pam-devel Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comhttp://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"Trying other mirror.http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"Trying other mirror.base                                                                                                                                                  | 3.6 kB  00:00:00     extras                                                                                                                                                | 2.9 kB  00:00:00     updates                                                                                                                                               | 2.9 kB  00:00:00     updates/7/x86_64/primary_db                                                                                                                           |  27 MB  00:00:04     Resolving Dependencies--> Running transaction check---> Package pam-devel.x86_64 0:1.1.8-23.el7 will be installed--> Processing Dependency: pam(x86-64) = 1.1.8-23.el7 for package: pam-devel-1.1.8-23.el7.x86_64--> Running transaction check---> Package pam.x86_64 0:1.1.8-22.el7 will be updated---> Package pam.x86_64 0:1.1.8-23.el7 will be an update--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================================================Installing: pam-devel x86_64 1.1.8-23.el7 base 185 kUpdating for dependencies: pam x86_64 1.1.8-23.el7 base 721 k
Transaction Summary=============================================================================================================================================================================Install 1 PackageUpgrade ( 1 Dependent package)
Total size: 905 kTotal download size: 185 kIs this ok [y/d/N]: y  #输入y进行确认,表示安装Downloading packages:warning: /var/cache/yum/x86_64/7/base/packages/pam-devel-1.1.8-23.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY ] 0.0 B/s | 0 B --:--:-- ETA Public key for pam-devel-1.1.8-23.el7.x86_64.rpm is not installedpam-devel-1.1.8-23.el7.x86_64.rpm | 185 kB 00:00:00 Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 From : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7Is this ok [y/N]: y #输入y进行确认,表示安装Running transaction checkRunning transaction testTransaction test succeededRunning transaction Updating : pam-1.1.8-23.el7.x86_64 1/3 Installing : pam-devel-1.1.8-23.el7.x86_64 2/3 Cleanup : pam-1.1.8-22.el7.x86_64 3/3 Verifying : pam-1.1.8-23.el7.x86_64 1/3 Verifying : pam-devel-1.1.8-23.el7.x86_64 2/3 Verifying : pam-1.1.8-22.el7.x86_64 3/3
Installed: pam-devel.x86_64 0:1.1.8-23.el7
Dependency Updated: pam.x86_64 0:1.1.8-23.el7
Complete!
复制

2.10 remove移除软件包

#参数-y则不用确认直接卸载,安装也是一样[root@centos yum.repos.d]# yum remove -y pam-develLoaded plugins: fastestmirror, langpacksResolving Dependencies--> Running transaction check---> Package pam-devel.x86_64 0:1.1.8-23.el7 will be erased--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================================================Removing: pam-devel x86_64 1.1.8-23.el7 @base 528 k
Transaction Summary=============================================================================================================================================================================Remove 1 Package
Installed size: 528 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Erasing : pam-devel-1.1.8-23.el7.x86_64 1/1 Verifying : pam-devel-1.1.8-23.el7.x86_64 1/1
Removed: pam-devel.x86_64 0:1.1.8-23.el7
Complete!
复制

2.11 使用-y选项不用确认直接安装软件包

[root@centos yum.repos.d]# yum -y install pam-devel Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comResolving Dependencies--> Running transaction check---> Package pam-devel.x86_64 0:1.1.8-23.el7 will be installed--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================================================Installing: pam-devel x86_64 1.1.8-23.el7 base 185 k
Transaction Summary=============================================================================================================================================================================Install 1 Package
Total download size: 185 kInstalled size: 528 kDownloading packages:pam-devel-1.1.8-23.el7.x86_64.rpm | 185 kB 00:00:00 Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : pam-devel-1.1.8-23.el7.x86_64 1/1 Verifying : pam-devel-1.1.8-23.el7.x86_64 1/1
Installed: pam-devel.x86_64 0:1.1.8-23.el7
Complete!
复制

2.12 只下载不安装

[root@centos ~]# yumdownloader bzip2Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfilebzip2-1.0.6-13.el7.x86_64.rpm    [root@centos ~]# yumdownloader rsyncLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfilersync-3.1.2-4.el7.x86_64.rpm [root@centos ~]# ll......-rw-r--r--. 1 root root  53120 Nov 25  2015 bzip2-1.0.6-13.el7.x86_64.rpm-rw-r--r--. 1 root root 412928 Apr 25  2018 rsync-3.1.2-4.el7.x86_64.rpm......
复制

【总结】

    yum中常见的选项和参数就介绍到这里啦!还有很多参数,如果有喜欢学习的可以使用--help参数进行查看学习啦。英文也比较简单,看一下就会知道的,常用的就整理到这里啦!

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论