yum用法


一、关于yum

yum(全称为 Yellow dogUpdater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

yum的命令形式一般是如下:yum[options] [command] [package ...]

其中的[options]是可选的,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装的过程)等等。[command]为所要进行的操作,[package ...]是操作的对象。

 

1、可以使用yum info packageName来查看包的安装情况。如下:

[root@localhost yum.repos.d]#yum info vsftpd

Loaded plugins: fastestmirror,refresh-packagekit, security

Loading mirror speeds from cached hostfile

Installed Packages

Name       : vsftpd

Arch       : x86_64

Version    : 2.2.2

Release    : 14.el6

Size       : 332 k

Repo       : installed

From repo  : base

Summary    : Very Secure Ftp Daemon

URL        : http://vsftpd.beasts.org/

License    : GPLv2 with exceptions

Description : vsftpd is a Very Secure FTPdaemon. It was written completely from

           : scratch.

如果已经安装了某软件,再使用yum安装时,会有如下提示:

[root@localhost~]# yum install -y ncurses

Loadedplugins: fastestmirror, refresh-packagekit, security

Loadingmirror speeds from cached hostfile

 * base: mirrors.skyshe.cn

 * extras: mirrors.yun-idc.com

 * updates: mirrors.skyshe.cn

...省略...

Tryingother mirror.

Settingup Install Process

Packagencurses-5.7-4.20090207.el6.x86_64 already installed and latest version

Nothing to do

[root@localhost~]# 

 

 

 

 

 

 

 

 

 

二、添加源

    有时候,系统自带的源不能满足我们的需求,就需要我们自己添加相关的源。如下操作:

1、先进入yum源配置目录

[root@localhost~]# cd /etc/yum.repos.d

 

2、备份系统自带的yum源

[root@localhost~]# mv CentOS-Base.repo CentOS-Base.repo.save

 

3、使用wget得到163的源

[root@localhostyum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

--2015-09-2210:45:49-- http://mirrors.163.com/.help/CentOS6-Base-163.repo

Resolvingmirrors.163.com... 123.58.173.186, 123.58.173.185

Connectingto mirrors.163.com|123.58.173.186|:80... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:2006 (2.0K) [application/octet-stream]

Savingto: 鈥淐entOS6-Base-163.repo鈥

100%[==============================================>]2,006       --.-K/s   in 0s     

2015-09-2210:45:49 (116 MB/s) - 鈥淐entOS6-Base-163.repo鈥saved [2006/2006]

 

注意:这里需要配好DNS,要不对163的域名无法解析,导致不能wget。

 

4、检查新源的完整性

[root@localhostyum.repos.d]# yum repolist all

Loadedplugins: fastestmirror, refresh-packagekit, security

Loadingmirror speeds from cached hostfile

base                                                            | 3.7 kB     00:00    

http://mirrors.163.com/centos/6/extras/x86_64/repodata/repomd.xml:[Errno 12] Timeout onhttp://mirrors.163.com/centos/6/extras/x86_64/repodata/repomd.xml: (28,'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')

Tryingother mirror.

http://mirrors.163.com/centos/6/updates/x86_64/repodata/repomd.xml:[Errno 12] Timeout onhttp://mirrors.163.com/centos/6/updates/x86_64/repodata/repomd.xml: (28,'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')

Tryingother mirror.

repoid                       repo name                                   status

C6.0-base                     CentOS-6.0 - Base                           disabled

C6.0-centosplus               CentOS-6.0 - CentOSPlus                     disabled

C6.0-contrib                  CentOS-6.0 - Contrib                        disabled

C6.0-extras                   CentOS-6.0 - Extras                         disabled

C6.0-updates                  CentOS-6.0 - Updates                        disabled

C6.1-base                     CentOS-6.1 - Base                           disabled

C6.1-centosplus               CentOS-6.1 - CentOSPlus                     disabled

C6.1-contrib                  CentOS-6.1 - Contrib                        disabled

C6.1-extras                   CentOS-6.1 - Extras                         disabled

C6.1-updates                  CentOS-6.1 - Updates                        disabled

C6.2-base                     CentOS-6.2 - Base                           disabled

C6.2-centosplus               CentOS-6.2 - CentOSPlus                     disabled

C6.2-contrib                  CentOS-6.2 - Contrib                        disabled

C6.2-extras                   CentOS-6.2 - Extras                         disabled

C6.2-updates                  CentOS-6.2 - Updates                        disabled

C6.3-base                     CentOS-6.3 - Base                           disabled

C6.3-centosplus               CentOS-6.3 - CentOSPlus                     disabled

C6.3-contrib                  CentOS-6.3 - Contrib                        disabled

C6.3-extras                   CentOS-6.3 - Extras                         disabled

C6.3-updates                  CentOS-6.3 - Updates                        disabled

base                          CentOS-6 - Base -163.com                   enabled: 6,575

c6-media                      CentOS-6 - Media                            disabled

centosplus                    CentOS-6 - Plus -163.com                   disabled

contrib                       CentOS-6 - Contrib -163.com                disabled

debug                         CentOS-6 -Debuginfo                        disabled

extras                        CentOS-6 - Extras - 163.com                 enabled:    35

updates                       CentOS-6 - Updates -163.com                enabled:   298

repolist:6,908

 

5、清理掉旧包的信息

[root@localhostyum.repos.d]# yum clean all

Loadedplugins: fastestmirror, refresh-packagekit, security

Cleaningrepos: base extras updates

Cleaningup Everything

Cleaningup list of fastest mirrors

[root@localhostyum.repos.d]# yum install -y vsftpd

Loadedplugins: fastestmirror, refresh-packagekit, security

Determiningfastest mirrors

base                                                            | 3.7 kB     00:00     

base/primary_db                                                 | 4.6 MB     00:07     

extras                                                           | 3.4 kB     00:00    

extras/primary_db                                               |  27 kB     00:00    

updates                                                         | 3.4 kB     00:00     

updates/primary_db                                               | 1.3MB     00:01     

Settingup Install Process

ResolvingDependencies

-->Running transaction check

--->Package vsftpd.x86_64 0:2.2.2-14.el6 will be installed

-->Finished Dependency Resolution

 

DependenciesResolved

 

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

Package            Arch               Version                   Repository        Size

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

Installing:

vsftpd             x86_64             2.2.2-14.el6              base             152 k

 

TransactionSummary

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

Install       1 Package(s)

 

Totaldownload size: 152 k

Installedsize: 332 k

DownloadingPackages:

vsftpd-2.2.2-14.el6.x86_64.rpm                                   | 152kB     00:00     

Runningrpm_check_debug

RunningTransaction Test

TransactionTest Succeeded

RunningTransaction

  Installing : vsftpd-2.2.2-14.el6.x86_64                                           1/1

  Verifying : vsftpd-2.2.2-14.el6.x86_64                                           1/1

 

Installed:

  vsftpd.x86_64 0:2.2.2-14.el6                                                          

 

Complete!

 

到此,新源添加完毕,可以使用了。

 

这里还有个命令 yum makecache ,将服务器端的软件包信息在本地缓存一下,以提高搜索、安装软件的速度。

对于我们不想要的包,可以采用yum remove命令删除。yum deplist命令可用来查看依赖关系。


评论

© 听雨残荷 | Powered by LOFTER