CentOS6.5-安装yum方法

Posted fangpinz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS6.5-安装yum方法相关的知识,希望对你有一定的参考价值。

1、卸载原有系统中的yum
rpm –qa | grep yum | xargs rpm -e --nodeps
(xargs 把rpm –qa | grep yum传来的每一行信息 都用xargs后面的命令进行处理)

2、创建一个目录intallyum_mirrors.163.com,进入此目录下载rpm包。

下载yum安装文件
注意,如果下载时找不到文件,就登录到:http://mirrors.163.com/centos/6/os/x86_64/ 上查找相应的安装包的包名,对以下包名进行修改,再进行下载。
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm

3、在当前installyum_mirrors.163.com目录下执行ls |grep yum |xargs rpm -ivh --nodeps
[root@Apache installyum_mirrors.163.com]# ls |grep yum |xargs rpm -ivh --nodeps
Preparing...                ########################################### [100%]
   1:yum-metadata-parser    ########################################### [ 33%]
   2:yum-plugin-fastestmirro########################################### [ 67%]
   3:yum                    ########################################### [100%]
[root@Apache installyum_mirrors.163.com]#

如果出现此安装所依赖的其他安装包没有安装,就继续wget 下载所依赖的安装包到installyum_mirrors.163.com目录下,继续ls |grep yum |xargs rpm -ivh --nodeps安装

直到yum安装成功。

4、备份/etc/yum.repos.d目录下的repo文件

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak

5、从mirrors.163.com上面下载reop文件。

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

6、设置CentOS6-Base-163.repo不更新可以更新的安装包,编辑以下[updates]中的enabled=0即可,如果配置中无enabled,那么是默认配置了enabled=1,需要添加enabled=0关闭update。

[updates] name=CentOS-$releasever - Updates - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

enabled=0

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

7、yum clean all   

8、yum makecache 

8、yum search vsftpd  测试yum功能是否OK

 

yum list  #显示本地所有已经安装和远端可以安装的程序包 //第3列有@的是已安装的软件包,没有@的是未安装,当前可以安装的程序包。

[root@fangpinz zfp]# yum list
已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn

已安装的软件包

GConf2.x86_64                                                                     3.2.6-8.el7                                                                 @anaconda
GeoIP.x86_64                                                                      1.5.0-14.el7                                                                @anaconda
ModemManager.x86_64                                                               1.6.10-4.el7                                                                @anaconda
ModemManager-glib.x86_64                                                          1.6.10-4.el7                                                                @anaconda
NetworkManager.x86_64                                                             1:1.18.8-2.el7_9                                                            @updates 
NetworkManager-adsl.x86_64                                                        1:1.18.8-2.el7_9                                                            @updates

.......

......

zip.x86_64                                                                        3.0-11.el7                                                                  @anaconda
zlib.x86_64                                                                       1.2.7-18.el7                                                                @anaconda
可安装的软件包
0ad.x86_64                                                                        0.0.22-1.el7                                                                epel     
0ad-data.noarch                                                                   0.0.22-1.el7                                                                epel     
0install.x86_64                                                                   2.11-1.el7                                                                  epel     
2048-cli.x86_64                                                                   0.9.1-1.el7                                                                 epel     

.......

......

telnet.x86_64                                                                     1:0.17-66.el7                                                               updates  
telnet-server.x86_64                                                              1:0.17-66.el7                                                               updates  

......

rpm 也可以检查,程序包在本地是否已经安装上了,可以这样看,把yum list 的程序包的包名一分为二,然后将第2列的信息放在中间,例如yum list中的zip.x86_64这个程序包用rpm在本地来查一下

[root@fangpinz zfp]# rpm -qa |grep zip-3.0-11.el7.x86_64
zip-3.0-11.el7.x86_64
[root@fangpinz zfp]#

像未安装的telnet,就本地查不到,

[root@fangpinz zfp]# rpm -qa |grep telnet
[root@fangpinz zfp]#

 

 

 

 

 

 

 

 

--------End Of Text--------

 

 

yum clean all   #会从系统中找$releasever和$basearch  如值为6和x86_64,然后生成/var/cache/yum/x86_64/6/base/packages/目录(目录里是空的)、cat /var/cache/yum/x86_64/6/extras/packages/(目录里是空的)等目录。

yum makecache  #从yum网络仓库获取元数据信息--本地建立元数据缓存,本地将元数据放在yum clean all生成的那些目录(/var/cache/yum/)中部署好。

 

PS:

/etc/yum.repos.d/CentOS6-Base-163.repo文件中的$releasever和$basearch的变量值是从哪里获取到的呢?从系统(例如arch、rpm -qi centos-release)中获取这些 built-in variables

 

yum 安装其他rpm包的时候,是从/etc/yum.repos.d/目录下寻找repo文件(.repo),找到之后会找enabled=1的baseurl的值,如果baseurl的值中含有$releasever和$basearch这样的变量存在,就去系统(arch、rpm -qi centos-release)中去找$releasever和$basearch的值,进而利用此baseurl访问yum网络仓库。如果baseurl被设置成无变量存在(sed -i  \'s/$releasever/6/g\' /etc/yum.repos.d/CentOS-Base.repo和sed -i  \'s/$baseurl/x86_64/g\' /etc/yum.repos.d/CentOS-Base.repo)的url,那么yum clean all (清空了本地元数据缓存)之后,yum就直接根据baseurl去访问yum网络仓库。当然repo文件可以直接到http://mirrors.163.com/.help/等网站目录中去下载。

 

以上是关于CentOS6.5-安装yum方法的主要内容,如果未能解决你的问题,请参考以下文章

centos6.5安装MySQL5.7(使用yum源安装方法)

CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误

CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误

centos6.5 系统-搭建lamp(php7)环境--(yum在线安装)

CentOS6.5 yum安装mysql5.7.18

centos6.5怎么安装yum