在linux环境中, 安装, 卸载更新包是一个极为常见的操作.大部分的linux环境都提供了包的管理工具, 例如:apt-get, dpkg, rpm, yum等等.

一些Linux环境中,yum是默认的包管理工具.Yum是Yellowdog Updater Modified的简称.

该文章阐释了经常被使用到yum命令的15个场景.

1> 使用yum install 安装包.

要安装一个包,使用 'yum install 包名'. 该命令将会自动的安装该包的依赖.

# yum install postgresql.x86_64
Resolving Dependencies
Install Package(s)
Is this ok [y/N]: y Package(s) data still to download: 3.0 M
(/): postgresql-9.0.-.fc15.x86_64.rpm | 2.8 MB :
(/): postgresql-libs-9.0.-.fc15.x86_64.rpm | kB :
------------------------------------------------------------------
Total kB/s | 3.0 MB : Running Transaction
Installing : postgresql-libs-9.0.-.fc15.x86_64 /
Installing : postgresql-9.0.-.fc15.x86_64 / Complete!

默认的'yum install'命令, 将会在安装这些包之前 提示你"接受"或"放弃", 如果想要使用yum自动安装包,而不对你进行提示. 使用 -y 选项. 如下所示:

# yum -y install postgresql.x86_64  

2> 使用yum remove 卸载包.

如下所示:使用'yum remove 包名' 命令卸载包.

# yum remove  postgresql.x86_64
Resolving Dependencies
---> Package postgresql.x86_64 :9.0.-.fc15 will be erased Is this ok [y/N]: y Running Transaction
Erasing : postgresql-9.0.-.fc15.x86_64 / Removed:
postgresql.x86_64 :9.0.-.fc15 Complete!

3> 使用 'yum update'命令升级已存在的包.

如果你的系统中存在一个旧版本的包, 使用'yum update 包名' 可以使它升级到最新版本. 当然,这个命令也会自动的找出并安装该报的所有必须的依赖.

# yum update postgresql.x86_64  

4> 使用'yum search'命令查找包. 

如果你不知道你想要安装的包的准确包名, 可以使用'yum search 关键字', 他将会搜索并列出匹配你的'关键字'的所有记录.

下面的实例是在yum的资源库中搜索所有匹配关键字'firefox'的包, 并且将其罗列出来.

# yum search firefox
Loaded plugins: langpacks, presto, refresh-packagekit
============== N/S Matched: firefox ======================
firefox.x86_64 : Mozilla Firefox Web browser
gnome-do-plugins-firefox.x86_64 : gnome-do-plugins for firefox
mozilla-firetray-firefox.x86_64 : System tray extension for firefox
mozilla-adblockplus.noarch : Adblocking extension for Mozilla Firefox
mozilla-noscript.noarch : JavaScript white list extension for Mozilla Firefox Name and summary matches only, use "search all" for everything.

5> 使用'yum info' 查看包的额外信息.

一旦你使用yum search搜索到了一个包, 你就可以使用'yum info 包名' 来查看该包的额外信息.

下面的例子展示了 'samba-common'包的额外信息.

# yum info samba-common.i686
Loaded plugins: langpacks, presto, refresh-packagekit
Available Packages
Name : samba-common
Arch : i686
Epoch :
Version : 3.5.
Release : .fc15.
Size : 9.9 M
Repo : updates
Summary : Files used by both Samba servers and clients
URL : http://www.samba.org/
License : GPLv3+ and LGPLv3+
Description : Samba-common provides files necessary for both the server and client
: packages of Samba.

6> 使用yum list 查看所有可见包.

下面的命令将会列出yum 数据库中所有的可见包.

# yum list | less 

7> 使用 yum list installed 查看你自己系统中已经安装的包. 

# yum list installed | less  

8>  使用'yum provides 文件名' 可以查看该文件属于哪个包.

如果你想知道某个文件属于哪个包, 使用'yum provides'. 例如, 如想要知道 /etc/sysconfig/nfs 文见属于哪个包.可以使用如下命令.

# yum provides /etc/sysconfig/nfs
Loaded plugins: langpacks, presto, refresh-packagekit
:nfs-utils-1.2.-.fc15.x86_64 : NFS utilities and supporting clients and
: daemons for the kernel NFS server
Repo : fedora
Matched from:
Filename : /etc/sysconfig/nfs :nfs-utils-1.2.-.fc15.x86_64 : NFS utilities and supporting clients and
: daemons for the kernel NFS server
Repo : updates
Matched from:
Filename : /etc/sysconfig/nfs :nfs-utils-1.2.-.fc15.x86_64 : NFS utilities and supporting clients and
: daemons for the kernel NFS server
Repo : installed
Matched from:
Other : Provides-match: /etc/sysconfig/nfs

 9> 使用yum grouplist 查看可见的"软件集合",

在yum 中,在一个指定的软件集合中,一些有关系的包被归类在一起, 你可以简单滴安装整个"软件集合"来安装所有该集合下的所有包, 而不是一个个的搜索和安装每个独立的包.

如下所示. 你可以执行"yum grouplist"来查看所有可见的"软件集合", 列出的三个已安装"集合"有, 已安装语言, 可见"软件集合."

# yum grouplist  

Installed Groups:
Administration Tools
Base
Design Suite
.... Installed Language Groups:
Arabic Support [ar]
Armenian Support [hy]
Bengali Support [bn]
.... Available Groups:
Authoring and Publishing
Books and Guides
Clustering
DNS Name Server
Development Libraries
Development Tools
Directory Server
Dogtag Certificate System
...

10> 使用"yum groupinstall" 安装指定的"软件集合".

如下示例中使用了'yum groupinstall' 功能来安装指定的软件集合 "DNS Name Server" 集合包含了bind 和bind-chroot.

# yum groupinstall 'DNS Name Server'  

Dependencies Resolved
Install Package(s)
Is this ok [y/N]: y Package(s) data still to download: 3.6 M
(/): bind-9.8.-.P4.fc15.x86_64.rpm | 3.6 MB :
(/): bind-chroot-9.8.-.P4.fc15.x86_64.rpm | kB :
-----------------------------------------------------------------
Total kB/s | 3.6 MB : Installed:
bind-chroot.x86_64 :9.8.-.P4.fc15 Dependency Installed:
bind.x86_64 :9.8.-.P4.fc15 Complete!

说明: 当然我们会稍后讨论如何使用yum groupinstall 安装mysql 数据库.

原文链接.http://www.thegeekstuff.com/2010/04/yum-groupinstall-mysql-database/

11>使用"yum groupupdate" 升级已存在的软件集合.

如果你已经使用 yum groupinstall 安装用了一个"软件集合",然后想要把它升级到最新的版本. 你可以使用如下命令.

# yum groupupdate 'Graphical Internet'  

Dependencies Resolved
Upgrade Package(s)
Is this ok [y/N]: y Running Transaction
Updating : evolution-data-server-3.0.-.fc15.x86_64 /
Updating : evolution-3.0.-.fc15.x86_64 /
Updating : evolution-NetworkManager-3.0.-.fc15.x86_64 /
Updating : evolution-help-3.0.-.fc15.noarch /
Updating : empathy-3.0.-.fc15.x86_64 /
Cleanup : evolution-NetworkManager-3.0.-.fc15.x86_64 /
Cleanup : evolution-help-3.0.-.fc15.noarch /
Cleanup : evolution-3.0.-.fc15.x86_64 /
Cleanup : empathy-3.0.-.fc15.x86_64 /
Cleanup : evolution-data-server-3.0.-.fc15.x86_64 / Complete!

12: 使用"yum groupremove" 来卸载软件集合.

好不容易装上了, 又升级到最新版本了. 又要卸载掉.有病吧.^_^.......

# yum groupremove 'DNS Name Server'
Dependencies Resolved
Remove Package(s)
Is this ok [y/N]: y Running Transaction
Erasing : :bind-chroot-9.8.-.P4.fc15.x86_64 /
Erasing : :bind-9.8.-.P4.fc15.x86_64 / Complete!

13>  使用"yum repolist"列出你当前的yum 资源库.

所有的yum命令"依赖"这一个或者多个yum资源库. 执行'yum repolist' 可以查看你系统中所有的yum资源库配置信息.

如下所列的只有可用的资源库.

# yum repolist
repo id repo name status
fedora Fedora - x86_64 ,
updates Fedora - x86_64 - Updates ,

如果想要查看所有的包含"可用"和"不可用"资源库, 使用"yum repolist all"

# yum repolist all
repo id repo name status
fedora Fedora - x86_64 enabled: ,
fedora-debuginfo Fedora - x86_64 - Debug disabled
fedora-source Fedora - Source disabled
rawhide-debuginfo Fedora - Rawhide - Debug disabled
rawhide-source Fedora - Rawhide - Source disabled
updates Fedora - x86_64 - Updates enabled: ,
updates-debuginfo Fedora - x86_64 - Updates - Debug disabled
updates-source Fedora - Updates Source disabled
updates-testing Fedora - x86_64 - Test Updates disabled
updates-testing-debuginfo Fedora - x86_64 - Test Updates Debug disabled
updates-testing-source Fedora - Test Updates Source disabled

如果想要查看不可用资源库. 使用 "yum repositories disabled"

14> 从不可用的资源库安装, 可用使用"yum -enablerepo"

yum默认的会从可用的资源库中安装文件. 不过某些原因下,你必须从不可用的资源库安装它, 那么你可以使用

-enablerepo参数.如下所示.

# yum --enablerepo=fedora-source install vim-X11.x86_64
Dependencies Resolved
Install Package(s)
Is this ok [y/N]: y Running Transaction
Installing : :vim-X11-7.3.-.fc15.x86_64 / Complete!

15> 使用Yum Shell 的方式来执行yum命令.

yum支持使用yum shell的方式来运行多个yum命令.

# yum shell
Setting up Yum Shell
> info samba.x86_64
Available Packages
Name : samba
Arch : x86_64
Epoch :
Version : 3.5.
Release : .fc15.
Size : 4.6 M
Repo : updates
Summary : Server and Client software to interoperate with Windows machines
URL : http://www.samba.org/
License : GPLv3+ and LGPLv3+
Description :
: Samba is the suite of programs by which a lot of PC-related
: machines share files, printers, and other information (such as
: lists of available files and printers). The Windows NT, OS/, and
: Linux operating systems support this natively, and add-on packages
: can enable the same thing for DOS, Windows, VMS, UNIX of all
: kinds, MVS, and more. This package provides an SMB/CIFS server
: that can be used to provide network services to SMB/CIFS clients.
: Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT
: need the NetBEUI (Microsoft Raw NetBIOS frame) protocol. >

当然, yum也可以从一个text文件中读取命令,然后一行行的执行, 对于你有多个系统的时候是非常有用的.

创建一个包含这些命令的text文件,然后使用 'yum shell'来执行这些命令, 而不必再每个系统上执行一样的命令.

# cat yum_cmd.txt
repolist
info nfs-utils-lib.x86_64 # yum shell yum_cmd.txt
repo id repo name status
fedora Fedora - x86_64 ,
updates Fedora - x86_64 - Updates , Available Packages
Name : nfs-utils-lib
Arch : x86_64
Version : 1.1.
Release : .fc15
Size : k
Repo : fedora
Summary : Network File System Support Library
URL : http://www.citi.umich.edu/projects/nfsv4/linux/
License : BSD
Description : Support libraries that are needed by the commands and
: daemons the nfs-utils rpm. Leaving Shell

15个Linux Yum命令实例--安装/卸载/更新的更多相关文章

  1. Linux系统 Centos7/Centos6.8 yum命令在线安装 MySQL5.6

    Linux系统 Centos7 yum命令在线安装 MySQL5.6 标签: centosmysqlyum 2015-11-18 17:21 707人阅读 评论(0) 收藏 举报  分类: Linux ...

  2. linux yum命令详解

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  3. linux yum命令详解-转

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  4. linux yum 命令

    linux yum 命令 yum( Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器. 基於RPM包管理,能够从指 ...

  5. 【转】linux yum命令详解

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  6. 【转发】linux yum命令详解

    linux yum命令详解 yum(全 称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理, ...

  7. linux yum 命令 详解

    linux yum命令详解 yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能 ...

  8. Linux -Yum 命令详解

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  9. <ZZ>linux yum命令详解

    http://www.cnblogs.com/chuncn/archive/2010/10/17/1853915.html yum(全称为 Yellow dog Updater, Modified)是 ...

随机推荐

  1. 【UVA 11865】 Stream My Contest (二分+MDST最小树形图)

    [题意] 你需要花费不超过cost元来搭建一个比赛网络.网络中有n台机器,编号0~n-1,其中机器0为服务器,其他机器为客户机.一共有m条可以使用的网线,其中第i条网线的发送端是机器ui,接收端是机器 ...

  2. SPRING IN ACTION 第4版笔记-第二章-004-Bean是否单例

    spring的bean默认是单例,加载容器是会被化,spring会拦截其他再次请求bean的操作,返回spring已经创建好的bean. It appears that the CompactDisc ...

  3. Java中x+=y和x=x+y两种实现的区别

    先看下边两段代码,各有什么错? 例一: short s1 = 1; s1 = s1 + 1; 例二: short s1 = 1; s1 += 1; 第一段代码无法通过编译,由于 s1+1 在运算时会自 ...

  4. bzoj1028

    穷举水题 ..] of boolean;     q:..] of longint;     ans,count,jud:..] of longint;     x,i,j,n,m,tot,t,k:l ...

  5. fsl的feat软件分包使用笔记

    introduction: 1. feat 是一种基于模型的fmri数据分析方法. 2. feat 首先使用顺手,至少看起来,比spm漂亮多了. feat是按照正常人的使用方法去设计的. spm 由于 ...

  6. 【转】Android中如何使用Bundle传递对象[使用Serializable或者Parcelable] -- 不错

    原文网址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1211/694.html Android中Bundle类的作用 Bun ...

  7. devi into python 笔记(六)正则表达式 原始字符串

    字符串函数replace: #string.replace: #字符串的replace方法:替换子串,不改变原来的字符串 s = "broad road" #打印出来会发现不单单是 ...

  8. Ajax初步实现页面局部内容更替

    类似于QQ邮箱的那种局部页面跳转,单页应用常用到,目前很多网页都是这种,但是弊端就是一次加载过多资源,首次加载卡出翔啊

  9. puppet任务计划

  10. 5 个在 Linux 中管理文件类型和系统时间的有用命令

    对于想学习 Linux 的初学者来说要适应使用命令行或者终端可能非常困难.由于终端比图形用户界面程序更能帮助用户控制 Linux 系统,我们必须习惯在终端中运行命令.因此为了有效记忆 Linux 不同 ...