CentOS7中YUM常见命令
1、列出所有软件包名称、版本信息
yum list installed
[root@centos7 ~]# yum list installed
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
GConf2.x86_64 3.2.6-8.el7 @anaconda
GeoIP.x86_64 1.5.0-14.el7 @anaconda
ModemManager.x86_64 1.6.10-3.el7_6 @anaconda
ModemManager-glib.x86_64 1.6.10-3.el7_6 @anaconda
NetworkManager.x86_64 1:1.18.4-3.el7 @anaconda
NetworkManager-adsl.x86_64 1:1.18.4-3.el7 @anaconda
NetworkManager-glib.x86_64 1:1.18.4-3.el7 @anaconda
NetworkManager-libnm.x86_64 1:1.18.4-3.el7 @anaconda
NetworkManager-libreswan.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-libreswan-gnome.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-ppp.x86_64 1:1.18.4-3.el7 @anaconda
NetworkManager-team.x86_64 1:1.18.4-3.el7 @anaconda
NetworkManager-tui.x86_64 1:1.18.4-3.el7 @anaconda
......
2、查询软件包描述信息
yum info 软件名称
例如:
1)了解软件包 kernel 的用途
软件包kernel主要提供Linux的运行内核程序:
[root@centos7 ~]# yum info kernel
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
名称 :kernel
架构 :x86_64
版本 :3.10.0
发布 :1127.el7
大小 :64 M
源 :installed
来自源:anaconda
简介 : The Linux kernel
网址 :http://www.kernel.org/
协议 : GPLv2
描述 : The kernel package contains the Linux kernel (vmlinuz), the core of any
: Linux operating system. The kernel handles the basic functions
: of the operating system: memory allocation, process allocation, device
: input and output, etc.
[root@centos7 ~]#
2)了解软件包 bash 的用途
软件包bash主要为Linux系统提供命令行解释器程序(/bin/bash):
[root@centos7 ~]# yum info bash
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
名称 :bash
架构 :x86_64
版本 :4.2.46
发布 :34.el7
大小 :3.5 M
源 :installed
来自源:anaconda
简介 : The GNU Bourne Again shell
网址 :http://www.gnu.org/software/bash
协议 : GPLv3+
描述 : The GNU Bourne Again shell (Bash) is a shell or command language
: interpreter that is compatible with the Bourne shell (sh). Bash
: incorporates useful features from the Korn shell (ksh) and the C shell
: (csh). Most sh scripts can be run by bash without modification.
[root@centos7 ~]#
3、查询哪些软件包能提供指定的程序/文件
yum provides “文件路径”
1)查询命令程序 vim 由哪个软件包提供
可以获知对应的软件包名称是 vim-enhanced:
[root@centos7 ~]# yum provides "*bin/vim"
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
2:vim-enhanced-7.4.629-6.el7.x86_64 : A version of the VIM editor which includes recent enhancements
源 :sss
匹配来源:
文件名 :/usr/bin/vim
2:vim-enhanced-7.4.629-6.el7.x86_64 : A version of the VIM editor which includes recent enhancements
源 :@sss
匹配来源:
文件名 :/usr/bin/vim
[root@centos7 ~]#
2)查询命令程序 ifconfig 由哪个软件包提供
可以获知对应的软件包名称是 net-tools:
[root@centos7 ~]# yum provides /sbin/ifconfig
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
源 :sss
匹配来源:
文件名 :/sbin/ifconfig
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
源 :@anaconda
匹配来源:
文件名 :/sbin/ifconfig
[root@centos7 ~]# ^C
4、yum安装/卸载软件
yum -y install 软件名 (可一次性安装多个软件)
yum -y remove 软件名(可一次性卸载多个软件)
1)安装 httpd、wireshark-gnome 软件包,观察执行过程
[root@centos7 ~]# yum -y install httpd wireshark-gnome
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 httpd-2.4.6-93.el7.centos.x86_64 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 wireshark-gnome.x86_64.0.1.10.14-24.el7 将被 安装
--> 正在处理依赖关系 wireshark = 1.10.14-24.el7,它被软件包 wireshark-gnome-1.10.14-24.el7.x86_64 需要
--> 正在处理依赖关系 libwsutil.so.3()(64bit),它被软件包 wireshark-gnome-1.10.14-24.el7.x86_64 需要
--> 正在处理依赖关系 libwiretap.so.3()(64bit),它被软件包 wireshark-gnome-1.10.14-24.el7.x86_64 需要
--> 正在处理依赖关系 libwireshark.so.3()(64bit),它被软件包 wireshark-gnome-1.10.14-24.el7.x86_64 需要
--> 正在检查事务
---> 软件包 wireshark.x86_64.0.1.10.14-24.el7 将被 安装
--> 正在处理依赖关系 libsmi.so.2()(64bit),它被软件包 wireshark-1.10.14-24.el7.x86_64 需要
--> 正在处理依赖关系 libcares.so.2()(64bit),它被软件包 wireshark-1.10.14-24.el7.x86_64 需要
--> 正在检查事务
---> 软件包 c-ares.x86_64.0.1.10.0-3.el7 将被 安装
---> 软件包 libsmi.x86_64.0.0.4.8-13.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================
正在安装:
wireshark-gnome x86_64 1.10.14-24.el7 sss 912 k
为依赖而安装:
c-ares x86_64 1.10.0-3.el7 sss 78 k
libsmi x86_64 0.4.8-13.el7 sss 2.3 M
wireshark x86_64 1.10.14-24.el7 sss 13 M
事务概要
=======================================================================================================================
安装 1 软件包 (+3 依赖软件包)
总下载量:16 M
安装大小:86 M
Downloading packages:
-----------------------------------------------------------------------------------------------------------------------
总计 61 MB/s | 16 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : c-ares-1.10.0-3.el7.x86_64 1/4
正在安装 : libsmi-0.4.8-13.el7.x86_64 2/4
正在安装 : wireshark-1.10.14-24.el7.x86_64 3/4
正在安装 : wireshark-gnome-1.10.14-24.el7.x86_64 4/4
验证中 : wireshark-1.10.14-24.el7.x86_64 1/4
验证中 : libsmi-0.4.8-13.el7.x86_64 2/4
验证中 : c-ares-1.10.0-3.el7.x86_64 3/4
验证中 : wireshark-gnome-1.10.14-24.el7.x86_64 4/4
已安装:
wireshark-gnome.x86_64 0:1.10.14-24.el7
作为依赖被安装:
c-ares.x86_64 0:1.10.0-3.el7 libsmi.x86_64 0:0.4.8-13.el7 wireshark.x86_64 0:1.10.14-24.el7
完毕!
[root@centos7 ~]#
2)检查这两个软件包的安装结果
[root@centos7 ~]# yum list httpd wireshark-gnome
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
httpd.x86_64 2.4.6-93.el7.centos @sss
wireshark-gnome.x86_64 1.10.14-24.el7 @sss
[root@centos7 ~]#
其中的wireshark-gnome提供了图形环境的抓包工具,通过“应用程序”–> “互联网”可以找到快捷方式,如图所示。
3)卸载 httpd 软件包,再次检查卸载结果
[root@centos7 ~]# yum -y remove httpd
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-93.el7.centos 将被 删除
--> 正在处理依赖关系 httpd-mmn = 20120211x8664,它被软件包 php-5.4.16-48.el7.x86_64 需要
--> 正在检查事务
---> 软件包 php.x86_64.0.5.4.16-48.el7 将被 删除
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================
正在删除:
httpd x86_64 2.4.6-93.el7.centos @sss 9.4 M
为依赖而移除:
php x86_64 5.4.16-48.el7 @sss 4.4 M
事务概要
=======================================================================================================================
移除 1 软件包 (+1 依赖软件包)
安装大小:14 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : php-5.4.16-48.el7.x86_64 1/2
正在删除 : httpd-2.4.6-93.el7.centos.x86_64 2/2
验证中 : php-5.4.16-48.el7.x86_64 1/2
验证中 : httpd-2.4.6-93.el7.centos.x86_64 2/2
删除:
httpd.x86_64 0:2.4.6-93.el7.centos
作为依赖被删除:
php.x86_64 0:5.4.16-48.el7
完毕!
[root@centos7 ~]# yum list httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
可安装的软件包 //提示该安装包可安装,即没有安装。
httpd.x86_64 2.4.6-93.el7.centos sss
[root@centos7 ~]#
5、通过重装软件修复误删的命令程序
yum -y reinstall vim-enhanced
1)删除文件 /usr/bin/vim ,检查 vim 编辑器是否还可用
[root@centos7 ~]# rm -rf /usr/bin/vim
[root@centos7 ~]# vim ./a.txt
-bash: /usr/bin/vim: 没有那个文件或目录 //vim编辑器程序已经缺失
[root@centos7 ~]#
2)使用 yum 安装 vim-enhanced 软件包,再次检查 vim 编辑器是否可用
尝试正常安装vim-enhanced软件包,会发现vim仍然不可用(因为此软件包已经安装过,直接install不会做更改)。
[root@centos7 ~]# yum -y install vim-enhanced
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 2:vim-enhanced-7.4.629-6.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@centos7 ~]#
[root@centos7 ~]# vim ./a.txt
-bash: /usr/bin/vim: 没有那个文件或目录
[root@centos7 ~]#
3)使用 yum 重装 vim-enhanced 软件包,再次检查 vim 编辑器是否可用
[root@centos7 ~]# yum -y reinstall vim-enhanced
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 vim-enhanced.x86_64.2.7.4.629-6.el7 将被 已重新安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================
重新安装:
vim-enhanced x86_64 2:7.4.629-6.el7 sss 1.1 M
事务概要
=======================================================================================================================
重新安装 1 软件包
总下载量:1.1 M
安装大小:2.2 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:vim-enhanced-7.4.629-6.el7.x86_64 1/1
验证中 : 2:vim-enhanced-7.4.629-6.el7.x86_64 1/1
已安装:
vim-enhanced.x86_64 2:7.4.629-6.el7
完毕!
[root@centos7 ~]#
[root@centos7 ~]# vim ./a.txt //vim可用
[root@centos7 ~]#