Redhat7 安装 yum

1. 备份原始yum源

# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
-rw-r--r--. 1 root root  358 Nov  7 13:17 redhat.repo
# mv redhat.repo redhat.repo.bak

2. 查看当前yum版本并卸载

# rpm -qa | grep yum
yum-3.4.3-154.el7.noarch
yum-rhn-plugin-2.0.1-9.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
# rpm -aq | grep yum|xargs rpm -e --nodeps

3. 前往下载yum包

在浏览器下载,再上传到Linux(使用xShell的xftp,可以直接拖拽进去):
链接:http://mirrors.163.com/centos/7/os/x86_64/Packages/

  1. python-iniparse-0.4-9.el7.noarch
  2. yum-3.4.3-167.el7.centos.noarch
  3. yum-metadata-parser-1.1.4-10.el7.x86_64
  4. yum-plugin-fastestmirror-1.1.31-53.el7.noarch

使用 wget命令 下载:

# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm

4. 进行安装:

# rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
warning: python-iniparse-0.4-9.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
	package python-iniparse-0.4-9.el7.noarch is already installed
	file /usr/lib/python2.7/site-packages/iniparse/ini.pyc from install of python-iniparse-0.4-9.el7.noarch conflicts with file from package python-iniparse-0.4-9.el7.noarch
	file /usr/lib/python2.7/site-packages/iniparse/ini.pyo from install of python-iniparse-0.4-9.el7.noarch conflicts with file from package python-iniparse-0.4-9.el7.noarc
# rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm 
warning: yum-metadata-parser-1.1.4-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [100%]
# rpm -ivh yum-3.4.3-167.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm 
warning: yum-3.4.3-167.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-plugin-fastestmirror-1.1.31-5################################# [ 50%]
   2:yum-3.4.3-167.el7.centos         ################################# [100%]

最后两个包一起装,不然会报错,他们之间存在依赖关系.

5. 更改yum源

这里使用网易的CentOS镜像源(也可以先下载再上传:http://mirrors.163.com/.help/CentOS6-Base-163.repo

# cd /etc/yum.repos.d/
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

把文件里面的 $releasever 全部替换为版本号:7,保存

# vim CentOS6-Base-163.repo
# :%s/$releasever/7/g

或者复制下面的repo:

# vim CentOS6-Base-163.repo

CentOS6-Base-163.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-7 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=t&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

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

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

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

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

阿里云yum源:

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

或者

# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

6. 清理yum缓存

# yum clean all
# yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度 (按照自己需要选择是否缓存) #

完成。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值