Linux yum命令:YUM管理器。
Linux yum命令 功能描述
使用yum命令可以安装、更新、删除、显示软件包和软件包组。yum可以自动进行系统更新,基于软件仓库的元数据分析,解决软件包依赖性关系。
Linux yum命令 语法
yum [选项] [命令]
命令中各选项的含义如表所示。
yum命令的命令部分描述如表所示。
要使用yum命令,必须事先配置好yum软件仓库。
Linux yum命令 示例
显示yum命令帮助信息
[root@rhel ~]# yum help
需要手工确认安装bind软件包
[root@rhel ~]# yum install bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================Package Arch Version Repository Size
===========================================================================
Installing:
bind x86_64 32:9.8.2-0.17.rc1.el6 rhel6 4.0 M
Transaction Summary
===========================================================================
Install 1 Package(s)
Total download size: 4.0 M
Installed size: 7.2 M
Is this ok[y/N]: y //输入y确认安装软件包
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing:32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Verifying :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Installed:
bind.x86_64 32:9.8.2-0.17.rc1.el6
Complete
无需确认直接安装bind软件包
[root@rhel ~]# yum -y install bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===========================================================================
Installing:
bind x86_64 32:9.8.2-0.17.rc1.el6 rhel6 4.0 M
Transaction Summary
===========================================================================
Install 1 Package(s)
Total download size: 4.0 M
Installed size: 7.2 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing:32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Verifying :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Installed:
bind.x86_64 32:9.8.2-0.17.rc1.el6
Complete!
安装以bin开头的软件包
[root@rhel ~]# yum -y install bin*
重新安装bind软件包
[root@rhel ~]# yum reinstall bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Reinstall Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6 will be reinstalled
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===========================================================================
Reinstalling:
bind x86_64 32:9.8.2-0.17.rc1.el6 rhel6 4.0 M
Transaction Summary
===========================================================================
Reinstall 1 Package(s)
Total download size: 4.0 M
Installed size: 7.2 M
Is this ok[y/N]: y //输入y确认重新安装软件包
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing:32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Verifying :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Installed:
bind.x86_64 32:9.8.2-0.17.rc1.el6
Complete!
显示bind软件包的详细信息
[root@rhel ~]# yum info bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Installed Packages
Name : bind
Arch : x86_64
Epoch :32
Version :9.8.2
Release :0.17.rc1.el6
Size :7.2 M
Repo : installed
From repo : rhel6
Summary : The Berkeley Internet Name Domain(BIND)DNS(Domain Name System)server
URL : http://www.isc.org/products/BIND/
License : ISC
Description : BIND (Berkeley Internet Name Domain) is an implementation of the DNS
: (Domain Name System) protocols. BIND includes a DNS server (named),
: which resolves host names to IP addresses; a resolver library
: (routines for applications to use when interfacing with DNS); and
: tools for verifying that the DNS server is operating properly.
显示所有已经安裝的软件包信息
[root@rhel ~]# yum info installed
列出bind软件包
[root@rhel ~]# yum list bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Installed Packages
bind.x86_64 32:9.8.2-0.17.rc1.el6 @rhel6
列出软件仓库中所有可以安装的软件包
[root@rhel ~]# yum list available
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Available Packages
389-ds-base.x86_64 1.2.11.15-11.el6 rhel6
389-ds-base-libs.i686 1.2.11.15-11.el6 rhel6
389-ds-base-libs.x86_64 1.2.11.15-11.el6 rhel6
DeviceKit-power.i686 014-3.el6 rhel6
ElectricFence.i686 2.2.2-28.el6 rhel6
ElectricFence.x86_64 2.2.2-28.el6 rhel6
GConf2.i686 2.28.0-6.el6 rhel6
GConf2-devel.i686 2.28.0-6.el6 rhel6
GConf2-devel.x86_64 2.28.0-6.el6 rhel6
ImageMagick.i686 6.5.4.7-6.el6_2 rhel6
ImageMagick.x86_64 6.5.4.7-6.el6_2 rhel6
ImageMagick-c++.x86_64 6.5.4.7-6.el6_2 rhel6
MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 rhel6
NetworkManager-glib.i686 1:0.8.1-43.el6 rhel6
........................(省略)
列出bind软件包的依赖关系
[root@rhel ~]# yum deplist bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Finding dependencies:
package: bind.x86_64 32:9.8.2-0.17.rc1.el6
dependency: liblwres.so.80()(64bit)
provider: bind-libs.x86_64 32:9.8.2-0.17.rc1.el6
dependency: grep
provider: grep.x86_64 2.6.3-3.el6
dependency: libc.so.6(GLIBC_2.4)(64bit)
provider: glibc.x86_64 2.12-1.107.el6
dependency: libz.so.1()(64bit)
provider: zlib.x86_64 1.2.3-29.el6
dependency: rtld(GNU_HASH)
provider: glibc.i686 2.12-1.107.el6
provider: glibc.x86_64 2.12-1.107.el6
dependency: portreserve
provider: portreserve.x86_64 0.0.4-9.el6
dependency: libpthread.so.0()(64bit)
provider: glibc.x86_64 2.12-1.107.el6
dependency: shadow-utils
provider: shadow-utils.x86_64 2:4.1.4.2-13.el6
dependency: libgssapi_krb5.so.2()(64bit)
provider: krb5-libs.x86_64 1.10.3-10.el6
dependency: libpthread.so.0(GLIBC_2.2.5)(64bit)
provider: glibc.x86_64 2.12-1.107.el6
........................(省略)
显示软件仓库的配置
[root@rhel ~]# yum repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id repo name status
rhel-source Red Hat Enterprise Linux 6Server-x86_64-Source 0
rhel-source-beta Red Hat Enterprise Linux 6Server Beta-x86_64-Source 0
rhel6 Red Hat Enterprise Linux 6 3,720
repolist: 3,720
查看/etc/named.conf文件是属于哪个软件包的
[root@rhel ~]# yum provides /etc/named.conf
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
32:bind-9.8.2-0.17.rc1.el6.x86_64: The Berkeley Internet Name Domain(BIND)DNS(Domain Name System)server
Repo : rhel6
Matched from:
Filename : /etc/named.conf
32:bind-9.8.2-0.17.rc1.el6.x86_64: The Berkeley Internet Name Domain(BIND)DNS(Domain Name System)server
Repo : installed
Matched from:
Other : Provides-match: /etc/named.conf
删除bind软件包
[root@rhel ~]# yum remove bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===========================================================================
Removing:
bind x86_64 32:9.8.2-0.17.rc1.el6 @rhel6 7.2 M
Transaction Summary
===========================================================================
Remove 1 Package(s)
Installed size: 7.2 M
Is this ok[y/N]: y //输入y确认删除软件包
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Verifying :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Removed:
bind.x86_64 32:9.8.2-0.17.rc1.el6
Complete!
从系统中删除bind软件包
[root@rhel ~]# yum erase bind
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===================================================================Removing:
bind x86_64 32:9.8.2-0.17.rc1.el6 @rhel6 7.2 M
Transaction Summary
=====================================================Remove 1 Package(s)
Installed size: 7.2 M
Is this ok[y/N]: y //输入y确认移除软件包
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Verifying :32:bind-9.8.2-0.17.rc1.el6.x86_64 1/1
Removed:
bind.x86_64 32:9.8.2-0.17.rc1.el6
Complete!
查找httpd软件包
[root@rhel ~]# yum search httpd
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
================================N/S Matched: httpd
==============================
httpd.x86_64 : Apache HTTP Server
httpd-devel.i686 : Development interfaces for the Apache HTTP server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support
Name and summary matches only, use ''search all'' for everything.
显示机器或可用仓库的版本
[root@rhel ~]# yum version
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Installed:6Server/x86_64 1120:e56d399d032780703b79e6923413c7f628ac5ebe
Group-Installed: yum 14:14e1c81c7a24520a8fcd1f7bae7472c9ebadd96d
version
运行交互式的yum shell
[root@rhel ~]# yum shell
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Yum Shell
>
生成源数据缓存
[root@rhel ~]# yum makecache
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-source |2.5 kB 00:00
rhel-source/filelists_db |1.2 MB 00:04
rhel-source/primary_db |1.4 MB 00:04
rhel-source/other_db |2.0 MB 00:05
rhel-source-beta |1.3 kB 00:00
rhel-source-beta/filelists | 205 B 00:00
rhel-source-beta/other | 201 B 00:00
rhel6 |2.9 kB 00:00...
rhel6/filelists_db |3.8 MB 00:00...
rhel6/other_db |1.6 MB 00:00...
Metadata Cache Created
确定哪个软件包提供了给定的依赖
[root@rhel ~]# yum resolvedep bind
检查可更新的软件包
[root@rhel ~]# yum check-update
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-source |2.5 kB 00:00
rhel-source/primary_db |1.4 MB 00:03
rhel-source-beta |1.3 kB 00:00
rhel-source-beta/primary | 214 B 00:00
rhel6 |2.9 kB 00:00...
rhel6/primary_db |3.1 MB 00:01...
显示yum使用历史
[root@rhel ~]# yum history
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
ID |Login user |Date and time |Action(s) |Altered
-------------------------------------------------------------------------------
11|root<root> |2013-08-19 02:41|Erase | 1
10|root<root> |2013-08-19 02:41|Install | 1
9|root<root> |2013-08-19 02:34|Erase | 1
8|root<root> |2013-08-19 02:19|Reinstall | 1
7|root<root> |2013-08-19 02:18|Install | 1
6|root<root> |2013-08-19 02:18|Erase | 3 EE
5|root<root> |2013-08-19 02:17|Install | 4
4|root<root> |2013-08-19 02:16|Install | 1
3|root<root> |2013-08-19 02:16|Erase | 1
2|root<root> |2013-08-19 02:11|Install | 1 <
1|System<unset> |2013-08-18 21:27|Install |1116>
history list
清除缓存目录下的软件包和旧的头文件
root@rhel ~]# ls /var/cache/yum/x86_64/6Server/rhel6
bead8b86e8dc93a754a45198d7758f9ea65b9afb7548a0b0d9afdf7c9decad27-primary.sqlite
cachecookie packages repomd.xml
//查看yum缓存目录/var/cache/yum/x86_64/6Server/rhel6的内容
[root@rhel ~]# yum clean all
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: rhel6
Cleaning up Everything
[root@rhel ~]# ls /var/cache/yum/x86_64/6Server/rhel6
packages
//再次查看/var/cache/yum/x86_64/6Server/rhel6目录,很多缓存数据已经没有了