yum( Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。

基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。

yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

yum 语法

<span class="pln">yum </span><span class="pun">[</span><span class="pln">options</span><span class="pun">]</span> <span class="pun">[</span><span class="pln">command</span><span class="pun">]</span> <span class="pun">[</span><span class="kwd">package</span> <span class="pun">...]</span>
  • options:可选,选项包括-h(帮助),-y(当安装过程提示选择全部为”yes”),-q(不显示安装的过程)等等。
  • command:要进行的操作。
  • package操作的对象。

yum常用命令

  • 1.列出所有可更新的软件清单命令:yum check-update
  • 2.更新所有软件命令:yum update
  • 3.仅安装指定的软件命令:yum install <package_name>
  • 4.仅更新指定的软件命令:yum update <package_name>
  • 5.列出所有可安裝的软件清单命令:yum list
  • 6.删除软件包命令:yum remove <package_name>
  • 7.查找软件包 命令:yum search <keyword>
  • 8.清除缓存命令:
    • yum clean packages: 清除缓存目录下的软件包
    • yum clean headers: 清除缓存目录下的 headers
    • yum clean oldheaders: 清除缓存目录下旧的 headers
    • yum clean, yum clean all (= yum clean packages; yum clean oldheaders) :清除缓存目录下的软件包及旧的headers

实例 1

安装 pam-devel

<span class="pun">[</span><span class="pln">root@www </span><span class="pun">~]#</span><span class="pln"> yum install pam</span><span class="pun">-</span><span class="pln">devel
</span><span class="typ">Setting</span><span class="pln"> up </span><span class="typ">Install</span> <span class="typ">Process</span>
<span class="typ">Parsing</span> <span class="kwd">package</span><span class="pln"> install arguments
</span><span class="typ">Resolving</span> <span class="typ">Dependencies</span>  <span class="pun"><==先检查软件的属性相依问题</span>
<span class="pun">--></span> <span class="typ">Running</span><span class="pln"> transaction check
</span><span class="pun">---></span> <span class="typ">Package</span><span class="pln"> pam</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">i386 </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span> <span class="kwd">set</span><span class="pln"> to be updated
</span><span class="pun">--></span> <span class="typ">Processing</span> <span class="typ">Dependency</span><span class="pun">:</span><span class="pln"> pam </span><span class="pun">=</span> <span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span> <span class="kwd">for</span> <span class="kwd">package</span><span class="pun">:</span><span class="pln"> pam</span><span class="pun">-</span><span class="pln">devel
</span><span class="pun">--></span> <span class="typ">Running</span><span class="pln"> transaction check
</span><span class="pun">---></span> <span class="typ">Package</span><span class="pln"> pam</span><span class="pun">.</span><span class="pln">i386 </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span> <span class="kwd">set</span><span class="pln"> to be updated
filelists</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">gz          </span><span class="lit">100</span><span class="pun">%</span> <span class="pun">|=========================|</span> <span class="lit">1.6</span><span class="pln"> MB    </span><span class="lit">00</span><span class="pun">:</span><span class="lit">05</span><span class="pln">
filelists</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">gz          </span><span class="lit">100</span><span class="pun">%</span> <span class="pun">|=========================|</span> <span class="lit">138</span><span class="pln"> kB    </span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span>
<span class="pun">-></span> <span class="typ">Finished</span> <span class="typ">Dependency</span> <span class="typ">Resolution</span>
<span class="pun">……(省略)</span>

实例 2

移除 pam-devel

<span class="pun">[</span><span class="pln">root@www </span><span class="pun">~]#</span><span class="pln"> yum remove pam</span><span class="pun">-</span><span class="pln">devel
</span><span class="typ">Setting</span><span class="pln"> up </span><span class="typ">Remove</span> <span class="typ">Process</span>
<span class="typ">Resolving</span> <span class="typ">Dependencies</span>  <span class="pun"><==同样的,先解决属性相依的问题</span>
<span class="pun">--></span> <span class="typ">Running</span><span class="pln"> transaction check
</span><span class="pun">---></span> <span class="typ">Package</span><span class="pln"> pam</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">i386 </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span> <span class="kwd">set</span><span class="pln"> to be erased
</span><span class="pun">--></span> <span class="typ">Finished</span> <span class="typ">Dependency</span> <span class="typ">Resolution</span>

<span class="typ">Dependencies</span> <span class="typ">Resolved</span>

<span class="pun">=============================================================================</span>
 <span class="typ">Package</span>                 <span class="typ">Arch</span>       <span class="typ">Version</span>          <span class="typ">Repository</span>        <span class="typ">Size</span>
<span class="pun">=============================================================================</span>
<span class="typ">Removing</span><span class="pun">:</span><span class="pln">
 pam</span><span class="pun">-</span><span class="pln">devel               i386       </span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span><span class="pln">   installed         </span><span class="lit">495</span><span class="pln"> k

</span><span class="typ">Transaction</span> <span class="typ">Summary</span>
<span class="pun">=============================================================================</span>
<span class="typ">Install</span>      <span class="lit">0</span> <span class="typ">Package</span><span class="pun">(</span><span class="pln">s</span><span class="pun">)</span>
<span class="typ">Update</span>       <span class="lit">0</span> <span class="typ">Package</span><span class="pun">(</span><span class="pln">s</span><span class="pun">)</span>
<span class="typ">Remove</span>       <span class="lit">1</span> <span class="typ">Package</span><span class="pun">(</span><span class="pln">s</span><span class="pun">)</span>  <span class="pun"><==还好,并没有属性相依的问题,单纯移除一个软件</span>

<span class="typ">Is</span> <span class="kwd">this</span><span class="pln"> ok </span><span class="pun">[</span><span class="pln">y</span><span class="pun">/</span><span class="pln">N</span><span class="pun">]:</span><span class="pln"> y
</span><span class="typ">Downloading</span> <span class="typ">Packages</span><span class="pun">:</span>
<span class="typ">Running</span><span class="pln"> rpm_check_debug
</span><span class="typ">Running</span> <span class="typ">Transaction</span> <span class="typ">Test</span>
<span class="typ">Finished</span> <span class="typ">Transaction</span> <span class="typ">Test</span>
<span class="typ">Transaction</span> <span class="typ">Test</span> <span class="typ">Succeeded</span>
<span class="typ">Running</span> <span class="typ">Transaction</span>
  <span class="typ">Erasing</span>   <span class="pun">:</span><span class="pln"> pam</span><span class="pun">-</span><span class="pln">devel                    </span><span class="com">######################### [1/1]</span>

<span class="typ">Removed</span><span class="pun">:</span><span class="pln"> pam</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">i386 </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span>
<span class="typ">Complete</span><span class="pun">!</span>

实例 3

利用 yum 的功能,找出以 pam 为开头的软件名称有哪些?

<span class="pun">[</span><span class="pln">root@www </span><span class="pun">~]#</span><span class="pln"> yum list pam</span><span class="pun">*</span>
<span class="typ">Installed</span> <span class="typ">Packages</span><span class="pln">
pam</span><span class="pun">.</span><span class="pln">i386                  </span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">3.27</span><span class="pun">.</span><span class="pln">el5      installed
pam_ccreds</span><span class="pun">.</span><span class="pln">i386           </span><span class="lit">3</span><span class="pun">-</span><span class="lit">5</span><span class="pln">                    installed
pam_krb5</span><span class="pun">.</span><span class="pln">i386             </span><span class="lit">2.2</span><span class="pun">.</span><span class="lit">14</span><span class="pun">-</span><span class="lit">1</span><span class="pln">               installed
pam_passwdqc</span><span class="pun">.</span><span class="pln">i386         </span><span class="lit">1.0</span><span class="pun">.</span><span class="lit">2</span><span class="pun">-</span><span class="lit">1.2</span><span class="pun">.</span><span class="lit">2</span><span class="pln">            installed
pam_pkcs11</span><span class="pun">.</span><span class="pln">i386           </span><span class="lit">0.5</span><span class="pun">.</span><span class="lit">3</span><span class="pun">-</span><span class="lit">23</span><span class="pln">               installed
pam_smb</span><span class="pun">.</span><span class="pln">i386              </span><span class="lit">1.1</span><span class="pun">.</span><span class="lit">7</span><span class="pun">-</span><span class="lit">7.2</span><span class="pun">.</span><span class="lit">1</span><span class="pln">            installed
</span><span class="typ">Available</span> <span class="typ">Packages</span> <span class="pun"><==底下则是『可升级』的或『未安装』的</span><span class="pln">
pam</span><span class="pun">.</span><span class="pln">i386                  </span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span>         <span class="kwd">base</span><span class="pln">
pam</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">i386            </span><span class="lit">0.99</span><span class="pun">.</span><span class="lit">6.2</span><span class="pun">-</span><span class="lit">4.el5</span>         <span class="kwd">base</span><span class="pln">
pam_krb5</span><span class="pun">.</span><span class="pln">i386             </span><span class="lit">2.2</span><span class="pun">.</span><span class="lit">14</span><span class="pun">-</span><span class="lit">10</span>              <span class="kwd">base</span>

国内 yum 源

网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错。

将yum源设置为163 yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本无法找到。

安装步骤

首先备份/etc/yum.repos.d/CentOS-Base.repo

<span class="pln">mv </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">yum</span><span class="pun">.</span><span class="pln">repos</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="typ">CentOS</span><span class="pun">-</span><span class="typ">Base</span><span class="pun">.</span><span class="pln">repo </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">yum</span><span class="pun">.</span><span class="pln">repos</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="typ">CentOS</span><span class="pun">-</span><span class="typ">Base</span><span class="pun">.</span><span class="pln">repo</span><span class="pun">.</span><span class="pln">backup</span>

下载对应版本 repo 文件, 放入 /etc/yum.repos.d/ (操作前请做好相应备份)

  • CentOS5 :http://mirrors.163.com/.help/CentOS5-Base-163.repo
  • CentOS6 :http://mirrors.163.com/.help/CentOS6-Base-163.repo
  • CentOS7 :http://mirrors.163.com/.help/CentOS7-Base-163.repo
<span class="pln">wget http</span><span class="pun">:</span><span class="com">//mirrors.163.com/.help/CentOS6-Base-163.repo</span><span class="pln">
mv </span><span class="typ">CentOS6</span><span class="pun">-</span><span class="typ">Base</span><span class="pun">-</span><span class="lit">163.repo</span> <span class="typ">CentOS</span><span class="pun">-</span><span class="typ">Base</span><span class="pun">.</span><span class="pln">repo</span>

运行以下命令生成缓存

<span class="pln">yum clean all
yum makecache</span>

除了网易之外,国内还有其他不错的 yum 源,比如中科大和搜狐。

中科大的 yum 源,安装方法查看:https://lug.ustc.edu.cn/wiki/mirrors/help/centos

sohu 的 yum 源安装方法查看: http://mirrors.sohu.com/help/centos.html