【导读】
yum,是Yellow dog Updater Modified的简称,起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(yellow dog updater),后经杜克大学的Linux@Duke开发团队进行改进,遂有此名。
【目录】
一 yum的选项与参数介绍
二 测试用例
一 yum的选项与参数介绍
clean Remove cached data
makecache Generate the metadata cache
search Search package details for the given string
list List a package or groups of packages
info Display details about a package or group of packages
provides 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, langpacks
Loading 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 library
dmraid-events.x86_64 : dmevent_tool (Device-mapper event tool) and DSO
iprutils.x86_64 : Utilities for the IBM Power Linux RAID adapters
mdadm.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 raid
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
[root@centos ~]# yum info mdadm
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
Name : mdadm
Arch : x86_64
Version : 4.0
Release : 13.el7
Size : 1.0 M
Repo : installed
From repo : anaconda
Summary : 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, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
GConf2.x86_64 3.2.6-8.el7 @anaconda
GeoIP.x86_64 1.5.0-11.el7 @anaconda
ModemManager.x86_64 1.6.10-1.el7 @anaconda
ModemManager-glib.x86_64 1.6.10-1.el7 @anaconda
NetworkManager.x86_64 1:1.10.2-13.el7 @anaconda
NetworkManager-adsl.x86_64 1:1.10.2-13.el7 @anaconda
NetworkManager-glib.x86_64 1:1.10.2-13.el7 @anaconda
Exiting on Broken Pipe
复制
2.4 updates列出系统上可升级的软件
[root@centos ~]# yum list updates
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
复制
2.5 provides查询命令是哪款软件提供的
[root@centos ~]# yum provides passwd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
passwd-0.79-4.el7.x86_64 : An utility for setting or changing passwords using PAM
Repo : @anaconda
[root@centos ~]# yum provides rsync
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
rsync-3.1.2-4.el7.x86_64 : A program for synchronizing files over a network
Repo : @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.repo
Resolving 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 OK
Length: 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" plugin
Loading "langpacks" plugin
Adding en_US.UTF-8 to language list
Config time: 0.020
Yum version: 3.4.3
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Setting up Package Sacks
pkgsack time: 0.039
Repo-id : base/7/x86_64
Repo-name : CentOS-7 - Base - mirrors.aliyun.com
Repo-revision: 1604001756
Repo-updated : Fri Oct 30 04:03:00 2020
Repo-pkgs : 10,072
Repo-size : 8.9 G
Repo-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:present
Repo-filename: /etc/yum.repos.d/CentOS-Base.repo
Repo-id : extras/7/x86_64
Repo-name : CentOS-7 - Extras - mirrors.aliyun.com
Repo-revision: 1712079707
Repo-updated : Wed Apr 3 01:41:49 2024
Repo-pkgs : 526
Repo-size : 1.0 G
Repo-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:present
Repo-filename: /etc/yum.repos.d/CentOS-Base.repo
Repo-id : updates/7/x86_64
Repo-name : CentOS-7 - Updates - mirrors.aliyun.com
Repo-revision: 1715095692
Repo-updated : Tue May 7 23:29:50 2024
Repo-pkgs : 5,886
Repo-size : 46 G
Repo-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:present
Repo-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, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
http://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 k
Updating for dependencies:
pam x86_64 1.1.8-23.el7 base 721 k
Transaction Summary
=============================================================================================================================================================================
Install 1 Package
Upgrade ( 1 Dependent package)
Total size: 905 k
Total download size: 185 k
Is 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 installed
pam-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-7
Importing 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-7
Is this ok [y/N]: y #输入y进行确认,表示安装
Running transaction check
Running transaction test
Transaction test succeeded
Running 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-devel
Loaded plugins: fastestmirror, langpacks
Resolving 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 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running 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, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving 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 k
Installed size: 528 k
Downloading packages:
pam-devel-1.1.8-23.el7.x86_64.rpm | 185 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running 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 bzip2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
bzip2-1.0.6-13.el7.x86_64.rpm
[root@centos ~]# yumdownloader rsync
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
rsync-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进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。