yum命令应用

记录:322

场景:在CentOS 7.9操作系统上,使用yum命令安装、卸载、下载、更新、查看软件包;使用yum命令查看镜像仓库信息、创建镜像元数据等。

版本:

操作系统:CentOS 7.9

名词:

YUM,Yellow dog Updater Modified的简称。一个在线软件安装工具。在Fedora和RedHat以及CentOS操作系统中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

1.yum基础环境

1.1配置yum源

使用yum命令安装软件前提基础,需配置一个正确的yum源,可以是本地镜像仓库,也可以是远程镜像仓库。本例使用阿里云镜像仓库。

阿里云镜像地址:https://mirrors.aliyun.com/

(1)yum源配置文件目录

目录:/etc/yum.repo.d

(2)下载Centos-7的yum源配置文件到本地

 命令:curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

(3)下载epel-7.repo的yum源配置文件到本地

命令:curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

(4)清空并刷新缓存

命令:yum clean all && yum makecache

1.2安装基础包

安装yum-utils命令:yum install -y yum-utils

安装net-tools命令:yum install -y net-tools.x86_64

安装perl命令:yum install -y perl

2.yum常用命令

(1)查看帮助

命令:yum --help

功能:查看yum支持全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

(2)安装软件

安装命令:yum install -y yum-utils

安装指定版本:yum install -y yum-utils-1.1.31

功能:安装指定名称的软件包。-y,安装过程中交互的提出的问题都同意。不加-y,交互过程中国需要手动输入yes,继续下一步;输入no,立即终止安装。软件包后不带版本,默认是安装镜像仓库中最新的包,带版本就按照指定版本安装,如果版本不存在就提示,没有包和Error: Nothing to do。

(3)重新安装软件

安装命令:yum reinstall -y yum-utils

功能:重装软件包。

(4)卸载软件

命令:yum erase -y yum-utils

命令:yum remove -y yum-utils

功能:卸载已安装的软件包。

(5)清空缓存数据和创建元数据缓存

命令:yum clean all && yum makecache

命令:yum clean all

命令:yum makecache

功能:yum clean all,清空缓存数据。yum makecache,创建元数据缓存。

(6)搜索软件包

命令:yum search yum-utils

功能:根据包名或者关键字在yum镜像仓库搜索包。

(7)查看镜像仓库软件包清单

命令:yum list yum-util

功能:列出镜像仓库中所有包名称和对应版本以及隶属仓库。

(8)在仓库列表和搜索列表中显示重复的包名

仓库列表:yum list --showduplicates yum-utils

搜索列表:yum search --showduplicates yum-utils

功能:yum list和yum search命令,使用--showduplicates选项时,把重复的包都列出。

(9)查看已安装包列表

查看已安装包列表:yum list installed

在已安装包列表搜索指定包:yum list installed | grep yum-utils

功能:查看系统中全量已经安装的软件包;使用grep查看指定包是否在已安装列表中。

(10)下载包

命令:yum install --downloadonly --downloaddir /home/mirror/ yum-utils

功能:使用yum install命令,只下载安装包rpm包到本地目录,不安装软件包。使用这种方式可以下载包,离线安装软件。

(11)列出镜像仓库

命令:yum repolist

功能:列出yum源配置的镜像仓库名称和仓库中软件包数量。

(12)查软件包详细信息

查看指定软件包信息:yum info yum-utils

查看全部软件包信息:yum info

功能:查看软件包信息,比如软件包名称、架构、版本、大小、仓库、摘要、URL、许可证描述等。英文:Name、Arch、Version、Release、Size、Repo、From repo、Summary 、URL、License、Description。

(13)查看使用记录

命令:yum history

功能:查看使用记录,主要包括Install、Reinstall、Erase等命令的使用。

(14)查看组信息

命令:yum groups

功能;查看可使用组信息。

(15)更新包

命令:yum update

功能:对比系统已经安装的包和仓库中包版本,系统中包版本低于仓库包,就会更新。

3.yum命令和选项

命令:yum --help

功能:查看yum支持全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

Loaded plugins: fastestmirror
Usage: yum [options] COMMAND

List of Commands:

check          Check for problems in the rpmdb
check-update   Check for available package updates
clean          Remove cached data
deplist        List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade      downgrade a package
erase          Remove a package or packages from your system
fs             Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot     Creates filesystem snapshots, or lists/deletes current snapshots.
groups         Display, or use, the groups information
help           Display a helpful usage message
history        Display, or use, the transaction history
info           Display details about a package or group of packages
install        Install a package or packages on your system
list           List a package or groups of packages
load-transaction load a saved transaction from filename
makecache      Generate the metadata cache
provides       Find what package provides the given value
reinstall      reinstall a package
repo-pkgs      Treat a repo. as a group of packages, so we can install/remove all of them
repolist       Display the configured software repositories
search         Search package details for the given string
shell          Run an interactive yum shell
swap           Simple way to swap packages, instead of using shell
update         Update a package or packages on your system
update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
updateinfo     Acts on repository update information
upgrade        Update packages taking obsoletes into account
version        Display a version for the machine and/or available repos.


Options:
  -h, --help            show this help message and exit
  -t, --tolerant        be tolerant of errors
  -C, --cacheonly       run entirely from system cache, don't update cache
  -c [config file], --config=[config file]
                        config file location
  -R [minutes], --randomwait=[minutes]
                        maximum command wait time
  -d [debug level], --debuglevel=[debug level]
                        debugging output level
  --showduplicates      show duplicates, in repos, in list/search commands
  -e [error level], --errorlevel=[error level]
                        error output level
  --rpmverbosity=[debug level name]
                        debugging output level for rpm
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  -y, --assumeyes       answer yes for all questions
  --assumeno            answer no for all questions
  --version             show Yum version and exit
  --installroot=[path]  set install root
  --enablerepo=[repo]   enable one or more repositories (wildcards allowed)
  --disablerepo=[repo]  disable one or more repositories (wildcards allowed)
  -x [package], --exclude=[package]
                        exclude package(s) by name or glob
  --disableexcludes=[repo]
                        disable exclude from main, for a repo or for
                        everything
  --disableincludes=[repo]
                        disable includepkgs for a repo or for everything
  --obsoletes           enable obsoletes processing during updates
  --noplugins           disable Yum plugins
  --nogpgcheck          disable gpg signature checking
  --disableplugin=[plugin]
                        disable plugins by name
  --enableplugin=[plugin]
                        enable plugins by name
  --skip-broken         skip packages with depsolving problems
  --color=COLOR         control whether color is used
  --releasever=RELEASEVER
                        set value of $releasever in yum config and repo files
  --downloadonly        don't update, just download
  --downloaddir=DLDIR   specifies an alternate directory to store packages
  --setopt=SETOPTS      set arbitrary config and repo options
  --bugfix              Include bugfix relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory=ADVS, --advisories=ADVS
                        Include packages needed to fix the given advisory, in
                        updates
  --bzs=BZS             Include packages needed to fix the given BZ, in
                        updates
  --cves=CVES           Include packages needed to fix the given CVE, in
                        updates
  --sec-severity=SEVS, --secseverity=SEVS
                        Include security relevant packages matching the
                        severity, in updates

以上,感谢。

2022年11月18日

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值