一、yum命令的基本安装功能
[[email protected] ~]# man yum
command is one of:
* install package1 [package2] [...]: install + 包名
yum -y: 安装时自动回答为yes
* reinstall package1 [package2] [...]: 重新安装
*** 补充rmp命令:rpm -ql + 包名 : 查询包安装生成的文件清单
rpm -qf + /path/to/file_name: 查询某文件是由哪个软件包生成的
* provides | whatprovides feature1 [feature2] [...]
使用yum来查询软件包生成哪些文件,以及文件是由哪个软件包生成的。
* update [package1] [package2] [...]: 升级版本,可加多个包
* update-to [package1] [package2] [...]: 指定升级到哪个版本
* downgrade package1 [package2] [...] : 降级
* check-update: 安装前检查有哪些可以升级的软件包
* upgrade [package1] [package2] [...]
* upgrade-to [package1] [package2] [...]
这两个命令已经被update取代了
* remove | erase package1 [package2] [...]
清除软件包:使用yum来清除包会同时清除它被依赖的包
* search string1 [string2] [...] : 只记得部分字符,可以进行模糊查询
* groupinstall group1 [group2] [...] :组安装:
1) 针对RHEL 6:
Development tools + Server Platform Development + Desktop Platform Development
2) 针对RHEL 5:
Development tools + development libraries
安装了这些这些组之后,就可以编译rpm包了,即将源码制作成二进制格式包
* groupupdate group1 [group2] [...] 升级组
* groupremove group1 [group2] [...] 移除组
* localinstall yum除了可以自动安装外,也可以将软件包下载到本地,然后手动安装
1)RHEL 6:
统一使用yum install 来安装即可
2)RHEL 5:
需要使用yum localinstall 来安装,同样手动升级可以使用yum localupdate,RHEL6处于兼容性需求,也支持这样的用法。
yum安装软件包最大的优势在于可以自动解决依赖关系
-- nogpgcheck :
对比rpm包,yum即使使用了localinstall,也会检查软件包的来源合法性,如果密钥无法匹配,则下载到本地的软件包也无法使用yum安装,故可以使用长选项 --nogpgcheck来避免检查
* history : 查看此前的安装卸载等操作历史
二、yum命令安装实例演示
/*-------- (1) 基本安装 --------*/
[[email protected] ~]# yum install bind-chroot
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Package 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 already installed and latest version Nothing to do # 已经安装了最新版,无需安装
现在先卸载这个软件包
[[email protected] ~]# rpm -e bind-chroot
grep: /etc/sysconfig/named: No such file or directory
[[email protected] ~]# rpm -e bind-chroot --force
rpm: only installation, upgrading, rmsource and rmspec may be forced
[[email protected] ~]# rpm -e bind-chroot
error: package bind-chroot is not installed
[[email protected] ~]# yum install bind-chroot
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed --> Processing Dependency: bind = 32:9.8.2-0.17.rc1.el6_4.6 for package: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed --> Finished Dependency Resolution #依赖关系自动解决 Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================== Installing: bind-chroot x86_64 32:9.8.2-0.17.rc1.el6_4.6 base 71 k Installing for dependencies: bind x86_64 32:9.8.2-0.17.rc1.el6_4.6 base 4.0 M Transaction Summary ========================================================================= Install 2 Package(s) Total download size: 4.0 M Installed size: 7.3 M Is this ok [y/N]: # 输入y表示安装,N表示不安装,默认为不安装,yum可以使用-y自动回答安装 Is this ok [y/N]: y Downloading Packages: -------------------------------------------------------------------------------- Total 42 MB/s | 4.0 MB 00:00 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_4.6.x86_64 1/2 Installing : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 2/2 Verifying : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 1/2 Verifying : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 2/2 Installed: bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 Dependency Installed: bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 Complete!
/*-------- (2) 重新安装 --------*/
[[email protected] ~]# yum install bind
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Package 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 already installed and latest version Nothing to do # 提示已经安装过了
[[email protected] ~]# yum reinstall bind
# 不论是否安装,都会重新安装一遍 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Reinstall Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 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_4.6 base 4.0 M Transaction Summary =============================================================================== Reinstall 1 Package(s) Total download size: 4.0 M Installed size: 7.3 M Is this ok [y/N]: 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_4.6.x86_64 1/1 Verifying : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 1/1 Installed: bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 Complete!
/*-------- (3) 卸载软件包 --------*/
[[email protected] ~]# yum remove bind
Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be erased --> Processing Dependency: bind = 32:9.8.2-0.17.rc1.el6_4.6 for package: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 --> Running transaction check ---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 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_4.6 @base 7.3 M Removing for dependencies: bind-chroot x86_64 32:9.8.2-0.17.rc1.el6_4.6 @base 0.0 # 清除bind的同时会清除bind-chroot,因为bind-chroot是依赖于bind的 Transaction Summary ============================================================================== Remove 2 Package(s) Installed size: 7.3 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Erasing : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 1/2 Erasing : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 2/2 warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave Verifying : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 1/2 Verifying : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 2/2 Removed: bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 Dependency Removed: bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 Complete!
/*-------- (4)软件包安装信息查询 --------*/
[[email protected] ~]# rpm -qf /etc/inittab
initscripts-9.03.40-2.el6.centos.x86_64
[[email protected] ~]# rpm -qf /etc/fstab
setup-2.8.14-20.el6_4.1.noarch
[[email protected] ~]# yum provides /etc/fstab
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files # 此包生成了/etc/fstab Repo : base Matched from: Filename : /etc/fstab setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files Repo : installed Matched from: Other : Provides-match: /etc/fstab
[[email protected] ~]# yum provides /etc/named.conf
#也可以显示没有安装的文件 Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) : server # 这个包之前被卸载了,这里显示的是服务器仓库上的包 Repo : base Matched from: Filename : /etc/named.conf
/*-------- (5) 模糊匹配查询 --------*/
[[email protected] ~]# yum search init
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile ==============================N/S Matched: init =============================== initscripts.x86_64 : The inittab file and the /etc/init.d scripts iscsi-initiator-utils-devel.x86_64 : Development files for ... upstart.x86_64 : An event-driven init system xhtml1-dtds.noarch : XHTML 1.0 document type definitions xorg-x11-xinit-session.x86_64 : Display manager support for ~/.xsession and ~/.Xclients Name and summary matches only, use "search all" for everything.
/*-------- (6) 安装包组 --------*/
通常安装开发环境,为避免依赖关系,通常需要安装三个组:Development tools; Server Platform Development; Desktop Platform Development
[[email protected] ~]# yum grouplist
Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Group Process Loading mirror speeds from cached hostfile base/group_gz | 220 kB 00:00 ... Installed Groups: Additional Development Base Debugging Tools ... Web Server X Window System Installed Language Groups: Arabic Support [ar] ... Venda Support [ve] Available Groups: Backup Client ... iSCSI Storage Client Available Language Groups: Afrikaans Support [af] ... Zulu Support [zu] Done
[[email protected]~]#yum -y groupinstall "Development tools" "Server Platform Development" "Desktop Platform Development"
... pixman-devel x86_64 0.26.2-5.el6_4 base 18 k ppl x86_64 0.10.2-11.el6 base 1.3 M systemtap-client x86_64 2.3-3.el6 base 3.4 M systemtap-devel x86_64 2.3-3.el6 base 1.4 M xorg-x11-proto-devel noarch 7.6-25.el6 base 274 k yajl x86_64 1.0.7-3.el6 base 27 k Transaction Summary ============================================================================== Install 115 Package(s) Total download size: 123 M Installed size: 404 M ... systemtap-devel.x86_64 0:2.3-3.el6 xorg-x11-proto-devel.noarch 0:7.6-25.el6 yajl.x86_64 0:1.0.7-3.el6 Complete!
/*-------- (7) 通过yum下载到本地,然后手动安装软件包 --------*/
[[email protected] ~]# cd /media/cdrom/Packages/
[[email protected] Packages]# yum install bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm
# 这个包已经下载到本地了,因此不再从服务器下载 Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Examining bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm: 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 Marking bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 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_4.6 /bind-9.8.2-0.17.rc1.el6_4.6.x86_64 7.3 M Transaction Summary ========================================================================================== Install 1 Package(s) Total size: 7.3 M Installed size: 7.3 M Is this ok [y/N]: N
[[email protected] Packages]# yum localinstall bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm
Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Local Package Process Examining bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 Marking bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm to be installed Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed --> Processing Dependency: bind = 32:9.8.2-0.17.rc1.el6_4.6 for package: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed --> Finished Dependency Resolution # 可以看到使用localinstall 也会自动解决依赖关系 Dependencies Resolved ========================================================================================= Package Arch Version Repository Size ========================================================================================== Installing: bind-chroot x86_64 32:9.8.2-0.17.rc1.el6_4.6 /bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 0.0 Installing for dependencies: bind x86_64 32:9.8.2-0.17.rc1.el6_4.6 base 4.0 M Transaction Summary ========================================================================================== Install 2 Package(s) Total download size: 4.0 M Installed size: 7.3 M Is this ok [y/N]: n Exiting on user Command
/*-------- (8) 查看yum命令的历史记录 --------*/
[[email protected] ~]# yum history
Loaded plugins: fastestmirror, refresh-packagekit, security ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 5 | root <root> | 2014-08-17 06:53 | Install | 115 4 | root <root> | 2014-08-17 06:37 | Erase | 2 EE 3 | root <root> | 2014-08-17 06:20 | Reinstall | 1 2 | root <root> | 2014-08-17 06:16 | Install | 2 < 1 | System <unset> | 2014-07-09 21:22 | Install | 1205 > history list