redhat下yum命令用法举例

发布时间:2020-11-27编辑:脚本学堂
本文介绍了redhat linux下yum命令的用法,需要的朋友参考下。

本节内容:
yum命令使用方法

yum源的配置,请参考:

本文主要讲解如何使用yum命令?一起来了解下。

yum命令的操作实例:
 

[root@serv01 ~]# yum --help 
Loaded plugins: product-id, subscription-manager 
Updating Red Hat repositories. 
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 
groupinfo      Display details about a package group 
groupinstall   Install the packages in a group on your system 
grouplist      List available package groups 
groupremove    Remove the packages in a group from your system 
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 
repolist       Display the configured software repositories 
resolvedep     Determine which package provides the given dependency 
search         Search package details for the given string 
shell          Run an interactive yum shell 
update         Update a package or packages on your system 
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 
  --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 
  --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 
  --setopt=SETOPTS      set arbitrary config and repo options 
 
  Plugin Options: 
 
#不建议使用这种方式卸载 
[root@serv01 ~]# yum remove nagios-common 
 
#yum安装的包,可以使用rpm命令查询到 
[root@serv01 ~]# rpm -qa | grep httpd 
httpd-tools-2.2.15-9.el6.x86_64 
httpd-2.2.15-9.el6.x86_64 
[root@serv01 ~]# ls /etc/httpd/conf/httpd.conf  
/etc/httpd/conf/httpd.conf 
#我们删除一个文件,再次安装 
[root@serv01 ~]# rm -rf /etc/httpd/conf/httpd.conf  
[root@serv01 ~]# ls /etc/httpd/conf/httpd.conf  
ls: cannot access /etc/httpd/conf/httpd.conf: No such file or directory 
#安装不成功 
[root@serv01 ~]# yum install httpd -y 
Loaded plugins: product-id, subscription-manager 
Updating Red Hat repositories. 
Setting up Install Process 
Package httpd-2.2.15-9.el6.x86_64 already installed and latest version 
Nothing to do 
#使用reinstall重装 
[root@serv01 ~]# yum reinstall httpd -y 
Installed: 
  httpd.x86_64 0:2.2.15-9.el6                                                                                                          
Complete! 
 
#查询所有 
[root@serv01 ~]# yum list 
#可以安装的略 
#查询httpd,有@表示已经安装 
[root@serv01 ~]# yum list|grep httpd 
httpd.x86_64                          2.2.15-9.el6                     @rhel-iso 
httpd-tools.x86_64                    2.2.15-9.el6                     @rhel-iso 
httpd-devel.i686                      2.2.15-9.el6                     rhel-iso  
httpd-devel.x86_64                    2.2.15-9.el6                     rhel-iso  
httpd-manual.noarch                   2.2.15-9.el6                     rhel-iso  
#验证 
[root@serv01 ~]# rpm -qa|grep httpd 
httpd-tools-2.2.15-9.el6.x86_64 
httpd-2.2.15-9.el6.x86_64 
 
#软件组 
[root@serv01 ~]# yum grouplist 
 
[root@serv01 ~]# yum grouplist | grep Devel 
   Additional Development 
   Desktop Platform Development 
   Development tools 
   Server Platform Development 
 
#安装软件组,注意需要有双引号 
[root@serv01 ~]# yum groupinstall "Server Platform" -y 
 
#强烈不建议这样移除,这样很危险,可以看到最后把内核都移除了。 
[root@serv01 ~]# yum groupremove "Server Platform" -y 
[root@serv01 ~]# yum groupremove "Server Platform" --skip-broken --nogpgcheck 
 
#这样可以正确的使用groupinstall安装和使用groupremove移除,因为该软件组依赖不多 
[root@serv01 ~]# yum groupinstall "Emacs" -y 
Installed: 
  emacs.x86_64 1:23.1-21.el6                                                                                                           
Complete! 
[root@serv01 ~]# yum groupremove "Emacs" -y 
Removed: 
  emacs.x86_64 1:23.1-21.el6                                                                                                           
 
Complete!