yum命令常用参数
但是所有列出来的参数都是自己在虚拟机上试用,然后把过程复制下来的,有兴趣的可以自己去看详细的英文文档
检测更新:
[root@VM_12_107_centos ~]# yum check-update
已加载插件:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): extras/7/x86_64/primary_db | 151 kB 00:00:00
(2/4): epel/7/x86_64/updateinfo | 788 kB 00:00:00
(3/4): epel/7/x86_64/primary_db | 4.7 MB 00:00:00
(4/4): updates/7/x86_64/primary_db | 4.8 MB 00:00:00
Loading mirror speeds from cached hostfile
NetworkManager.x86_64 1:1.4.0-19.el7_3 updates
NetworkManager-libnm.x86_64 1:1.4.0-19.el7_3 updates
NetworkManager-team.x86_64 1:1.4.0-19.el7_3 updates
NetworkManager-tui.x86_64 1:1.4.0-19.el7_3 updates
abrt-libs.x86_64 2.1.11-45.el7.centos os
alsa-lib.x86_64 1.1.1-1.el7 os
alsa-tools-firmware.x86_64 1.1.0-1.el7 os
at.x86_64 3.1.13-22.el7 os
audit.x86_64 2.6.5-3.el7_3.1 updates
audit-libs.x86_64 2.6.5-3.el7_3.1 updates
authconfig.x86_64 6.2.8-14.el7 os
avahi-autoipd.x86_64 0.6.31-17.el7 os
avahi-libs.x86_64 0.6.31-17.el7
单独更新某一个工具:
[root@pyt-it36 ~]# yum update httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
aliyun | 3.7 kB 00:00
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-29.el6.centos will be updated
---> Package httpd.x86_64 0:2.2.15-59.el6.centos will be an update
--> Processing Dependency: httpd-tools = 2.2.15-59.el6.centos for package: httpd-2.2.15-59.el6.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be updated
---> Package httpd-tools.x86_64 0:2.2.15-59.el6.centos will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================================
Updating:
httpd x86_64 2.2.15-59.el6.centos aliyun 834 k
Updating for dependencies:
httpd-tools x86_64 2.2.15-59.el6.centos aliyun 79 k
Transaction Summary
=====================================================================================================================================================================================
Upgrade 2 Package(s)
Total download size: 913 k
根据关键字查找软件:
[root@pyt-it36 ~]# yum search yum-cron
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
=============================================================================== N/S Matched: yum-cron ===============================================================================
yum-cron.noarch : Files needed to run yum updates as a cron job
Name and summary matches only, use "search all" for everything.
安装软件:
[root@pyt-it36 ~]# yum -y install yum-cron.noarch
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum-cron.noarch 0:3.2.29-81.el6.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================================
如果需要的话,可以设置每天自动更新
~]# chkconfig yum-cron on
~]# service yum-cron start
~]# service yum-cron status
自动更新配置文件:/etc/sysconfig/yum-cron
旧一点的系统是这个:/etc/yum/yum-cron.conf
查看刚才安装的软件包:
[root@pyt-it36 ~]# rpm -qa | grep yum-cron
yum-cron-3.2.29-81.el6.centos.noarch
[root@pyt-it36 ~]#
查看刚才安装都装了什么文件到我们的系统
[root@pyt-it36 ~]#
[root@pyt-it36 ~]# rpm -ql yum-cron
/etc/cron.daily/0yum.cron
/etc/rc.d/init.d/yum-cron
/etc/sysconfig/yum-cron
/etc/yum/yum-daily.yum
/etc/yum/yum-weekly.yum
/usr/share/doc/yum-cron-3.2.29
/usr/share/doc/yum-cron-3.2.29/COPYING
/usr/share/man/man8/yum-cron.8.gz
模糊匹配列出软件包名,软件包组名:
[root@pyt-it36 ~]# yum list http*
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
httpd.x86_64 2.2.15-29.el6.centos @anaconda-CentOS-201311272149.x86_64/6.5
httpd-tools.x86_64 2.2.15-29.el6.centos @anaconda-CentOS-201311272149.x86_64/6.5
Available Packages
httpd.x86_64 2.2.15-59.el6.centos aliyun
httpd-devel.i686 2.2.15-59.el6.centos aliyun
httpd-devel.x86_64 2.2.15-59.el6.centos aliyun
httpd-manual.noarch 2.2.15-59.el6.centos aliyun
httpd-tools.x86_64 2.2.15-59.el6.centos aliyun
[root@pyt-it36 ~]#
可以一次列出多个:
[root@pyt-it36 ~]# yum list http* abrt*
列出已安装的包:
[root@pyt-it36 ~]# yum list installed
指定列出:
[root@pyt-it36 ~]# yum list installed "java*"
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.66.1.13.0.el6 @anaconda-CentOS-201311272149.x86_64/6.5
java-1.7.0-openjdk.x86_64 1:1.7.0.45-2.4.3.3.el6 @anaconda-CentOS-201311272149.x86_64/6.5
[root@pyt-it36 ~]#
列出所有可用的软件包(可以用yum命令安装的):
root@pyt-it36 ~]# yum list available
分组列出:
[root@pyt-it36 ~]# yum grouplist
列出使用的yum源:
[root@pyt-it36 ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id repo name status
aliyun aliyun-yum 6,706
repolist: 6,706
列出包的详细信息,包括已安装的和可用的:
[root@pyt-it36 ~]# yum info httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.2.15
Release : 29.el6.centos
Size : 2.9 M
Repo : installed
From repo : anaconda-CentOS-201311272149.x86_64
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
Available Packages
Name : httpd
Arch : x86_64
Version : 2.2.15
Release : 59.el6.centos
Size : 834 k
Repo : aliyun
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
还可以用repoquery 列出一个包所包含的所有文件(包括库):
[root@VM_12_189_centos scripts]# repoquery --list httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d
/etc/httpd/conf.modules.d/00-base.conf
查看某个包会被安装到哪个bin/sbin目录下:
[root@pyt-it36 ~]# yum provides "*bin/httpd"
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
httpd-2.2.15-59.el6.centos.x86_64 : Apache HTTP Server
Repo : aliyun
Matched from:
Filename : /usr/sbin/httpd
httpd-2.2.15-29.el6.centos.x86_64 : Apache HTTP Server
Repo : installed
Matched from:
Filename : /usr/sbin/httpd
列出软件包的组信息:
[root@bjdc-pytbackup ~]# yum grouplist kde*
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* epel: mirror01.idc.hinet.net
可用的环境分组:
KDE Plasma Workspaces
完成
查看更详细一点的软件包组信息:
[root@bjdc-pytbackup ~]# yum -v grouplist kde*
加载 "fastestmirror" 插件
加载 "langpacks" 插件
Adding en_US.UTF-8 to language list
Adding zh_CN.UTF-8 to language list
Config time: 0.008
Yum version: 3.4.3
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
设置软件包群集
Loading mirror speeds from cached hostfile
* epel: mirror01.idc.hinet.net
pkgsack time: 0.015
group time: 0.130
可用的环境分组:
KDE Plasma Workspaces (kde-desktop-environment)
完成
组交互安装(不想询问,直接安装加-y参数即可):
yum groupinstall groupname (groupname 上一个命令查)
oot@bjdc-pytbackup ~]# yum groupinstall KDE Plasma Workspaces
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 6.1 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql56-community | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): epel/x86_64/primary_db | 4.7 MB 00:00:01
(2/3): epel/x86_64/updateinfo | 790 kB 00:00:05
(3/3): updates/7/x86_64/primary_db | 4.8 MB 00:00:18
Loading mirror speeds from cached hostfile
* epel: mirror.lzu.edu.cn
Warning: group Plasma does not exist.
Warning: group Workspaces does not exist.
正在解决依赖关系
--> 正在检查事务
---> 软件包 abrt-desktop.x86_64.0.2.1.11-45.el7.centos 将被 安装
--> 正在处理依赖关系 abrt = 2.1.11-45.el7.centos,它被软件包 abrt-desktop-2.1.11-45.el7.centos.x86_64 需要
--> 正在处理依赖关系 libreport-plugin-mantisbt >= 2.1.11-34,它被软件包 abrt-desktop-2.1.11-45.el7.centos.x86_64 需要
--> 正在处理依赖关系 libreport-centos >= 2.1.11-34,它被软件包 abrt-desktop-2.1.11-45.el7.centos.x86_64 需要
--> 正在处理依赖关系 gnome-abrt,它被软件包 abrt-desktop-2.1.11-45.el7.centos.x86_64 需要
--> 正在处理依赖关系 abrt-gui,它被软件包 abrt-desktop-2.1.11-45.el7.centos.x86_64 需要
---> 软件包 akonadi.x86_64.0.1.9.2-4.el7 将被 安装
--> 正在处理依赖关系 qt4(x86-64) >= 4.8.5,它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libsoprano.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libboost_program_options-mt.so.1.53.0()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libQtXml.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libQtSql.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libQtNetwork.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libQtGui.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libQtDBus.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 libQtCore.so.4()(64bit),它被软件包 akonadi-1.9.2-4.el7.x86_64 需要
---> 软件包 akonadi-mysql.x86_64.0.1.9.2-4.el7 将被 安装
--> 正在处理依赖关系 qt4-mysql(x86-64),它被软件包 akonadi-mysql-1.9.2-4.el7.x86_64 需要
--> 正在处理依赖关系 mariadb-server,它被软件包 akonadi-mysql-1.9.2-4.el7.x86_64 需要
软件包 1:mariadb-server-5.5.52-1.el7.x86_64 被已安装的 mysql-community-server-5.6.31-2.el7.x86_64 取代
---> 软件包 ark.x86_64.0.4.10.5-4.el7 将被 安装
软件包卸载:
[root@bjdc-pytbackup ~]# yum remove httpd
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-40.el7.centos.1 将被 删除
--> 正在处理依赖关系 httpd-mmn = 20120211x8664,它被软件包 php-5.4.16-42.el7.x86_64 需要
--> 正在检查事务
---> 软件包 php.x86_64.0.5.4.16-42.el7 将被 删除
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================================================================
正在删除:
httpd x86_64 2.4.6-40.el7.centos.1 @updates 9.4 M
为依赖而移除:
php x86_64 5.4.16-42.el7 @base 4.4 M
事务概要
=====================================================================================================================================================================================
移除 1 软件包 (+1 依赖软件包)
安装大小:14 M
是否继续?[y/N]:y 【这里的y手动输入,不想安装输入n】
整组卸载:
yum groupremove group_name
yum remove @group
列出最近是20个yum安装/卸载历史记录:
[root@bjdc-pytbackup ~]# yum history list
已加载插件:fastestmirror, langpacks
ID | 命令行 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------
35 | -y install php-fpm php-g | 2017-05-04 11:34 | Install | 3
34 | -y install php | 2017-05-04 11:32 | I, U | 5
33 | -y install ipset.x86_64 | 2017-02-16 12:00 | Install | 3
32 | -y install docbook-style | 2017-02-16 12:00 | Install | 3
31 | -y install glib2-devel.x | 2017-02-16 12:00 | I, U | 2 P<
30 | -y install nload | 2017-01-04 09:23 | Install | 1 >
29 | install epel-release | 2017-01-04 09:23 | Install | 1 <
28 | -y install mysql-connect | 2016-10-21 09:16 | Install | 29 >
27 | -y install openssl-devel | 2016-10-08 11:14 | Update | 3
26 | -y install xinetd | 2016-10-08 11:13 | Install | 1
25 | update | 2016-07-01 00:43 | I, U | 56
24 | -y install psmisc | 2016-06-22 16:20 | Install | 1
23 | -y install tcl-devel | 2016-05-31 11:54 | Install | 1
22 | -y install libcurl-devel | 2016-05-31 10:50 | Install | 1
21 | -y install php-mysql | 2016-05-31 10:46 | Install | 1
20 | -y install perl-Time-HiR | 2016-05-30 20:29 | Install | 4
19 | -y install httpd | 2016-05-30 14:46 | Install | 1
18 | remove httpd | 2016-05-30 14:45 | Erase | 1 EE
17 | -y install libdbi libdbi | 2016-05-26 20:33 | Install | 1
16 | -y install libdbi-dbd-my | 2016-05-26 20:33 | Install | 3
history list
列出所有yum安装/卸载历史记录:
[root@bjdc-pytbackup ~]# yum history list all
已加载插件:fastestmirror, langpacks
ID | 登录用户 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------
35 | root <root> | 2017-05-04 11:34 | Install | 3
34 | root <root> | 2017-05-04 11:32 | I, U | 5
33 | root <root> | 2017-02-16 12:00 | Install | 3
32 | root <root> | 2017-02-16 12:00 | Install | 3
31 | root <root> | 2017-02-16 12:00 | I, U | 2 P<
30 | root <root> | 2017-01-04 09:23 | Install | 1 >
29 | root <root> | 2017-01-04 09:23 | Install | 1 <
28 | root <root> | 2016-10-21 09:16 | Install | 29 >
27 | root <root> | 2016-10-08 11:14 | Update | 3
26 | root <root> | 2016-10-08 11:13 | Install | 1
列出指定id的yum安装/卸载历史记录:
[root@bjdc-pytbackup ~]# yum history list 20 21 22
已加载插件:fastestmirror, langpacks
ID | 命令行 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------
22 | -y install libcurl-devel | 2016-05-31 10:50 | Install | 1
21 | -y install php-mysql | 2016-05-31 10:46 | Install | 1
20 | -y install perl-Time-HiR | 2016-05-30 20:29 | Install | 4
history list
[root@bjdc-pytbackup ~]#
根据id列出一个范围的历史记录:
[root@bjdc-pytbackup ~]# yum history list 10..15
已加载插件:fastestmirror, langpacks
ID | 命令行 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------
15 | -y install dovecot-mysql | 2016-05-26 16:58 | Install | 1
14 | -y install perl-DBD-MySQ | 2016-05-26 14:28 | Install | 1
13 | -y install elinks | 2016-05-26 11:51 | Install | 3
12 | -y install mysql-devel | 2016-05-24 21:43 | Install | 1
11 | install mysql-server | 2016-05-24 21:34 | Install | 4 E<
10 | update | 2016-05-24 21:16 | I, U | 111 >
history list
列出yum安装/卸载历史记录的概要信息:
[root@bjdc-pytbackup ~]# yum history summary
已加载插件:fastestmirror, langpacks
登录用户 | 时间 | 操作 | 变更数量
-------------------------------------------------------------------------------
root <root> | 最近一周 | I, U | 8
root <root> | 最近3个月 | I, U | 8
root <root> | 最近6个月 | Install | 2
root <root> | 最近一年 | E, I, U | 296
系统 <空> | 最近一年 | Install | 664
history summary
列出某个软件包的历史信息:
[root@bjdc-pytbackup ~]# yum history package-list httpd
已加载插件:fastestmirror, langpacks
ID | 操作 | Package
-------------------------------------------------------------------------------
19 | 安装 | httpd-2.4.6-40.el7.centos.1.x86_64
18 | 删除 | httpd-2.4.6-40.el7.centos.1.x86_64 EE
8 | 安装 | httpd-2.4.6-40.el7.centos.1.x86_64
history package-list
查看包的更多详细信息:
(后面那个是id,用yum history list all可以查到,id值可以换成一个范围,如10..13)
[root@bjdc-pytbackup ~]# yum history info 35
已加载插件:fastestmirror, langpacks
事务 ID: 35
起始时间 : Thu May 4 11:34:30 2017
启动 RPM 数据库 : 792:8541de55ece332e9ddf468a75eb369cc5bc31796
结束时间 : 11:34:35 2017 (5 秒)
结束 RPM 数据库 : 795:cc219c600008c467b7e7c869eb99763ebb02b011
用户 : root <root>
返回码 : 成功
命令行 : -y install php-fpm php-gd
事务完成属主:
已安装 rpm-4.11.3-17.el7.x86_64 @anaconda
已安装 yum-3.4.3-132.el7.centos.0.1.noarch @anaconda
已安装 yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
已变更的包:
安装 php-fpm-5.4.16-42.el7.x86_64 @base
安装 php-gd-5.4.16-42.el7.x86_64 @base
依赖安装 t1lib-5.1.2-14.el7.x86_64 @base
history info
yum history redo id
redo参数会重复执行一次该id的操作,比如,我们id=35是安装php-fpm,把id的值35替换到命令里,会重复安装一次
yum history undo id
undo就是做相反的操作,id=35是安装php-fpm,把35传入执行上面的命令,就会卸载php-fpm
yum-complete-transaction
yum安装过程中,系统崩溃等原因导致安装没完成的,可以使用这个命令继续完成安装
yum全局配置:
[root@bjdc-pytbackup ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
各个参数具体代表什么可以参考redhat官网的文章:
查看yum当前全局配置信息:
[root@bjdc-pytbackup ~]# yum-config-manager
已加载插件:fastestmirror, langpacks
===================================== main ===========================================
[main]
alwaysprompt = True
assumeno = False
assumeyes = False
autocheck_running_kernel = True
bandwidth = 0
bugtracker_url = http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
cache = 0
cachedir = /var/cache/yum/x86_64/7
check_config_file_age = True
clean_requirements_on_remove = False
color = auto
color_list_available_downgrade = dim,cyan
color_list_available_install = normal
color_list_available_reinstall = bold,underline,green
color_list_available_running_kernel = bold,underline
color_list_available_upgrade = bold,blue
color_list_installed_extra = bold,red
color_list_installed_newer = bold,yellow
color_list_installed_older = bold
color_list_installed_reinstall = normal
color_list_installed_running_kernel = bold,underl
把yum软件包的源数据缓存到本地:
yum makecache
清除源数据:
yum clean all/metadata/headers/plugins/rpmdb/
指定目录下载,不安装
yum install —downloadonly —downloaddir=/path/to/directory httpd
本文出自 “BYWIND” 博客,请务必保留此出处http://bywind.blog.51cto.com/7598847/1922482
原文地址:http://bywind.blog.51cto.com/7598847/1922482