博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

yum 使用

Posted on 2014-09-11 09:59  bw_0927  阅读(251)  评论(0)    收藏  举报

http://www.cnblogs.com/my_life/articles/6401269.html

 

yum whatprovides libstdc++.so.6

yum install libstdc++.so.6 --setopt=protected_multilib=false

 

yum list installed  

 

Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

vi /etc/yum.repos.d/epel.repo
查找https,改为http即可

 

yum repolist

yum makecache

 

yum deplist gdb  查看依赖

 

=================================

1.1. RPM、REPO 和 SPEC

CentOS 由于是基于 RHEL 的发行版,所以也使用同样的包管理体系, 二进制包和源码包都以 RPM(RedHat Package Manager)格式发布。

所有的软件包托管在 repo 中,repo 维护着所有 rpm 的 metadata 信息, 以便能够通过 yum 等命令对软件包进行安装/更新/卸载等操作。

而如果用户需要构建自己的 rpm 包,那么还需要编写 spec 文件,通过 spec 文件来构建 rpm 软件包,从而可以使用 rpm 或者 yum 命令来安装

1.1.1. RPM 版本号及名字格式

RPM 的版本由两部分组成:

  • Version,通常表示 upstream 社区发布的版本,例如:2.0,2.0.1 等
  • Release,发行版的本地更新,通常为整数以及发行版代号,例如:1,2,3,1.el6,2.el7 等

完整的 RPM 包名字遵守如下格式:

<package-name>-<Version>-<Release>.<arch>.<type>

例如:htop-2.0.0-2.el7.x86_64.rpm,其中:

  • package-name 是 htop
  • Version 是 2.0.0
  • Release 是 2.el7
  • arch 是 x86_64
  • type 是 rpm,如果是源码包,则是 src.rpm

1.2. rpm 和 yum 命令

CentOS 中可以通过 rpm 和 yum 两个命令来管理 rpm 软件包,通常来说:

  • rpm 用于查询本地已经安装的软件包
  • yum 用于和 repo 打交道:搜索可用的软件包,下载,安装,卸载等

这里简单介绍下 rpm 和 yum 的惯用法。

1.2.1. rpm 命令常见用法

下面的命令都以 htop 软件包作为示例。

查找是否已经安装了某个包

# rpm -qa | grep htop
htop-2.0.2-1.el7.x86_64

查看安装的软件包安装了哪些文件

# rpm -ql htop
/usr/bin/htop
/usr/share/doc/htop-2.0.2
/usr/share/doc/htop-2.0.2/AUTHORS
/usr/share/doc/htop-2.0.2/COPYING
/usr/share/doc/htop-2.0.2/ChangeLog
/usr/share/doc/htop-2.0.2/README
/usr/share/man/man1/htop.1.gz
/usr/share/pixmaps/htop.png

想知道本地文件来自那个软件包

# rpm -qf /usr/bin/htop
htop-2.0.2-1.el7.x86_64

1.2.2. yum 命令常见用法

下面的命令都以 htop 软件包作为示例。

从 repo 中查找某个软件包

# yum search htop
...
===================================================================================== N/S matched: htop ======================================================================================
htop-debuginfo.x86_64 : Debug information for package htop
htop.x86_64 : Interactive process viewer

  Name and summary matches only, use "search all" for everything.

从 repo 中查找哪个包提供了哪个文件

# yum provides /usr/bin/htop
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
htop-1.0.3-3.el7.x86_64 : Interactive process viewer
Repo        : epel
Matched from:
Filename    : /usr/bin/htop



htop-2.0.0-2.el7.x86_64 : Interactive process viewer
Repo        : epel
Matched from:
Filename    : /usr/bin/htop



htop-2.0.1-1.el7.x86_64 : Interactive process viewer
Repo        : epel
Matched from:
Filename    : /usr/bin/htop



htop-2.0.2-1.el7.x86_64 : Interactive process viewer
Repo        : epel
Matched from:
Filename    : /usr/bin/htop

或者,如果不知道具体的文件路径,输入部分也可以,例如:

# yum provides htop

安装软件包的最新版本

# yum install htop

查看软件包所有可用的版本

# yum --showduplicate list htop
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
htop.x86_64                                 2.0.2-1.el7                                 @epel-mesos
Available Packages
htop.x86_64                                 1.0.3-3.el7                                 epel
htop.x86_64                                 2.0.0-2.el7                                 epel
htop.x86_64                                 2.0.1-1.el7                                 epel
htop.x86_64                                 2.0.2-1.el7                                 epel

安装软件包的指定版本

# yum remove htop
# yum install htop-2.0.1-1.el7

或者,忽略 release 版本号(安装最新的 release 版本):

# yum remove htop
# yum install htop-2.0.0

注意:如果已经安装了 htop 最新版本,上面的命令不会再安装,所以先执行 remove 操作,或者使用 yum downgrade 来安装旧版本

降级软件包到指定版本(软件包的新版本已经安装)

# yum downgrade htop-2.0.0-2.el7

卸载软件包

# yum remove htop

删除 yum cache

# yum clean all

这会删掉所有 yum cache,包括 repo 的 metadata 以及下载的软件包(放心:不会卸载已经安装的软件包)。

重新下载 yum repo metadata

当你修改了 /etc/yum.repos.d/ 下面的 repo 文件之后,需要删除掉原来的 repo metadata,然后重新生成一次;否则,由于本地的 metadata cache 和远端 repo 服务器上的不一样,可能会导致 yum 命令失败。

# yum clean all
# yum makecache