RHEL6.4下安装yum-亲测

1、使用RedHat系统不能正常使用yum安装
由于RedHat没有注册,所有不能使用它自身的资源更新,于是使用yum instatll gcc-c++的时候出现This system is not registered with RHN,所以我们可以通过更换源来进行相关更新。
但是使用centOS7或者ubunt 16.0.4,可以直接使用yum 进行安装软件。
【其实我的初衷并不是如此,后面会提到】

   # rpm –qa|grep yum
   卸载安装源:
   # rpm -qa|grep yum|xargs rpm -e --nodeps
   确认卸载干净:
   # rpm –qa|grep yum

2、查找安装包
因为我的系统是:
[root@localhost yum]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@localhost yum]# uname -a
Linux localhost 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
所以在以下地址查找安装包:http://mirrors.163.com/centos/6/os/x86_64/Packages/ 【是的,RHEL6.4可以用这个】
python-iniparse-0.3.1-2.1.el6.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
yum-3.2.29-81.el6.centos.noarch.rpm
yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm
网上还有博主提到另外几个安装包【
python-urlgrabber-3.10-8.el7.noarch.rpm
python-2.6.6-66.el6_8.x86_64.rpm
yum-plugin-security-1.1.30-41.el6.noarch.rpm
yum-utils-1.1.30-41.el6.noarch.rpm
】,不过一是因为我安装了python3(也是我重新安装yum的初衷,后面会提到),二是因为5、6篇博文取交集,就是需要那4个啦。
3、安装yum
因文件有相互依赖性,注意顺序,故先安装python-iniparse-*.rpm 文件

rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm 
rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
rpm -ivh yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm --nodeps --force
注:rpm -ivh 要安装的rpm  --nodeps --force  (加上 --nodeps --force 为強制安裝,不管依赖性文件)
来自 <https://blog.csdn.net/zhuchunyan_aijia/article/details/79149128> 

4、修改来源文件
复制以下地址到浏览器自动下载 http://mirrors.163.com/.help/CentOS6-Base-163.repo
或使用wget 下载:服务器上执行[wget http://mirrors.163.com/.help/CentOS6-Base-163.repo]
cd /etc/yum.repos.d;cp rhel-source.repo rhel-source.repo_bak20180807 以进行备份
将下载到的文件上传至该目录,vi编辑其中的内容($releasever改成CentOS对应版本6,gpgcheck=0, gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6),
不下载该文件也行,直接备份原 rhel-source.repo文件之后,清空重新编辑如下:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=0
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=0
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

5、运行makecache生成缓存
将服务器软件包信息缓存至本地,提高搜索安装效率
/usr/bin/python2.6 /usr/bin/yum makecache 【为什么这样运行后面会提到】

6、运行yum clean all清理yum缓存
(等同于yum cleanheaders;yum cleanpackages)
/usr/bin/python2.6 /usr/bin/yum clean all

7、更新YUM文件
/usr/bin/python2.6 /usr/bin/yum update 【貌似会像应用商店一样把所有可以升级的软件都升级了,就不安装了】

Transaction Summary
======================================================================================
Install      31 Package(s)
Upgrade     558 Package(s)

Total download size: 545 M
Is this ok [y/N]: 

8、测试是否安装成功
就是安装两个软件,看能不能安装

/usr/bin/python2.6 /usr/bin/yum install vim
/usr/bin/python2.6 /usr/bin/yum install perl-DBI

9、参考博文
linux安装yum: https://blog.csdn.net/zhuchunyan_aijia/article/details/79149128
linux下yum安装及配置: https://www.cnblogs.com/kabi/p/5232420.html
Index of /centos/6/os/x86_64/Packages/: https://www.cnblogs.com/kabi/p/5232420.html

10、初衷
初衷是因为使用yum安装openssl的时候报错如下:
这里写图片描述
本来以为是系统自带的yum有问题,需要重装,实际上是“通过看报错可以了解到是使用了python2的语法,所以了解到当前yum使用的Python2,因为我单独安装了python3,且python3设置为默认版本了,所以导致语法问题”
来自 https://blog.csdn.net/ltz150/article/details/77870735
解决方法一:
一直使用 [/usr/bin/python2.6 /usr/bin/yum]的方式调用
解决方法二:
[root@localhost yum.repos.d]# vim /usr/bin/yum

#!/usr/bin/python2.6                                修改python为python2.6
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\

来自 <http://tool.oschina.net/highlight> 

猜你喜欢

转载自blog.csdn.net/FrankioLi/article/details/81478258