由于Redhat自带的yum须要注册,收费方可使用,而CentOS是免费的,因此我们安装centos7.0的yum,都说国内网易的源比较稳定,就用这个。
首先查看系统版本:cat /etc/redhat-release
[root@localhost Desktop]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
[root@localhost Desktop]#
然后删除系统自带yum
rpm -qa | grep yum | xargs rpm -e –nodeps
“查询所有安装包名字里含yum的,循环删除,不考虑依赖关系”
下载最新安装包RPM(http://mirrors.163.com/centos/7/os/x86_64/Packages/)
下面是最新版本 (先写在这,其实不用去下载)
wget [http://mirrors](http://mirrors/).[163.com/centos/7/os/x86_64/Packages/](http://163.com/centos/6/os/x86_64/Packages/)[yum-3.4.3-158.el7.centos.noarch.rpm](http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm)
wget [http://mirrors](http://mirrors/).[163.com/centos/7/os/x86_64/Packages/](http://163.com/centos/6/os/x86_64/Packages/)[yum-metadata-parser-1.1.4-10.el7.x86_64.rpm](http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm)
wget [http://mirrors](http://mirrors/).[163.com/centos/7/os/x86_64/Packages/](http://163.com/centos/6/os/x86_64/Packages/)[yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm](http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm)
wget [http://mirrors](http://mirrors/).[163.com/centos/7/os/x86_64/Packages/](http://163.com/centos/6/os/x86_64/Packages/)[yum-updateonboot-1.1.31-45.el7.noarch.rpm](http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-45.el7.noarch.rpm)
wget [http://mirrors](http://mirrors/).[163.com/centos/7/os/x86_64/Packages/](http://163.com/centos/6/os/x86_64/Packages/)[yum-utils-1.1.31-45.el7.noarch.rpm](http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm)
然后发现有坑:
第一个坑:按照安装提示,下载官网中相关的依赖文件,没想到一个一个下了好多个,还是安装不上yum
更坑的是下面这个,明明已经安装了python-urlgrabber 3.10-8版本,还是提示需要安装。
[root@localhost yum.repos.d]# rpm -ivh yum-3.4.3-158.el7.centos.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
warning: yum-3.4.3-158.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
python-urlgrabber >= 3.10-8 is needed by yum-3.4.3-158.el7.centos.noarch
rpm >= 0:4.11.3-22 is needed by yum-3.4.3-158.el7.centos.noarch
折腾了半天,在网上查找了资料,最后发现只能从低版本先开始安装,因此从国外网站下载了较低版本,我放在lower目录下面:
[root@localhost lower]# ls
yum-3.4.3-132.el7.centos.0.1.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
yum-updateonboot-1.1.31-34.el7.noarch.rpm
yum-utils-1.1.31-34.el7.noarch.rpm
这几个文件我放到百度网盘上,需要的朋友可以下载:
链接:https://pan.baidu.com/s/1QyH66a-F8nSvfMDCoYFEdA 密码:rs9a
之后rpm -ivh yum-* 安装
[root@localhost lower]# rpm -ivh yum-*
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 ################################# [ 33%]
2:yum-plugin-fastestmirror-1.1.31-3################################# [ 67%]
3:yum-3.4.3-132.el7.centos.0.1 ################################# [100%]
[root@localhost lower]# rpm -ivh yum-updateonboot-1.1.31-34.el7.noarch.rpm yum-utils-1.1.31-34.el7.noarch.rpm
warning: yum-updateonboot-1.1.31-34.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:yum-utils-1.1.31-34.el7 ################################# [ 50%]
2:yum-updateonboot-1.1.31-34.el7 ################################# [100%]
[root@localhost lower]#
现在看下已经安装完了
[root@localhost yum.repos.d]# rpm -aq | grep yum
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-updateonboot-1.1.31-34.el7.noarch
yum-utils-1.1.31-34.el7.noarch
yum-3.4.3-132.el7.centos.0.1.noarch
[root@localhost yum.repos.d]#
将centOS中的repo导入Redhat中的/etc/yum.repos.d中:
http://mirrors.163.com/.help/centos.html
打开上面链接并下载CentOS-Base-163.repo,拷贝到/etc/yum.repos.d目录下。 因为没有定义环境变量releasever, 我们把所有$releasever改成数字7
vim /etc/yum.repos.d/CentOS-Base-163.repo
改完后的内容如下,我也放到网盘里了:
[base]
name=CentOS-7 - Base
baseurl=[http://mirror.centos.org/centos/7/os/$basearch/](http://mirror.centos.org/centos/7/os/$basearch/)
gpgcheck=1
gpgkey=[file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7](file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7)
[updates]
name=CentOS-7- Updates
baseurl=[http://mirror.centos.org/centos/7/updates/$basearch/](http://mirror.centos.org/centos/7/updates/$basearch/)
gpgcheck=1
gpgkey=[file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7](file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7)
[extras]
name=CentOS-7 - Extras
baseurl=[http://mirror.centos.org/centos/7/extras/$basearch/](http://mirror.centos.org/centos/7/extras/$basearch/)
gpgcheck=1
gpgkey=[file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7](file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7)
[centosplus]
name=CentOS-7 - Plus
baseurl=[http://mirror.centos.org/centos/7/centosplus/$basearch/](http://mirror.centos.org/centos/7/centosplus/$basearch/)
gpgcheck=1
enabled=0
gpgkey=[file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7](file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7)
使其生效
yum clean all 清除原有缓存
[root@dockerServer yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: base epel extras updates
Cleaning up everything
yum makecache 获取yum列表
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/12): base/x86_64/group_gz | 166 kB 00:03
(2/12): base/x86_64/primary_db | 5.9 MB 00:14
(3/12): base/x86_64/other_db | 2.5 MB 00:02
(4/12): extras/x86_64/prestodelta | 100 kB 00:02
(5/12): base/x86_64/filelists_db | 6.9 MB 00:20
(6/12): extras/x86_64/primary_db | 204 kB 00:00
(7/12): extras/x86_64/other_db | 126 kB 00:00
(8/12): extras/x86_64/filelists_db | 603 kB 00:04
(9/12): updates/x86_64/prestodelta | 649 kB 00:02
(10/12): updates/x86_64/filelists_db | 3.2 MB 00:06
(11/12): updates/x86_64/other_db | 573 kB 00:01
(12/12): updates/x86_64/primary_db | 6.0 MB 00:05
Determining fastest mirrors
Metadata Cache Created
这个时候yum就可以使用了。
当然,如果你要更新到新版本,直接使用
yum update yum
[root@localhost yum.repos.d]# yum update yum
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package yum.noarch 0:3.4.3-132.el7.centos.0.1 will be updated
---> Package yum.noarch 0:3.4.3-158.el7.centos will be an update
--> Processing Dependency: rpm >= 4.11.3-22 for package: yum-3.4.3-158.el7.centos.noarch
--> Processing Dependency: python-urlgrabber >= 3.10-8 for package: yum-3.4.3-158.el7.centos.noarch
--> Running transaction check
---> Package python-urlgrabber.noarch 0:3.10-4.el7 will be updated
---> Package python-urlgrabber.noarch 0:3.10-8.el7 will be an update
---> Package rpm.x86_64 0:4.11.1-16.el7 will be updated
--> Processing Dependency: rpm = 4.11.1-16.el7 for package: rpm-python-4.11.1-16.el7.x86_64
--> Processing Dependency: rpm = 4.11.1-16.el7 for package: rpm-libs-4.11.1-16.el7.x86_64
---> Package rpm.x86_64 0:4.11.3-32.el7 will be an update
--> Running transaction check
---> Package rpm-libs.x86_64 0:4.11.1-16.el7 will be updated
--> Processing Dependency: rpm-libs(x86-64) = 4.11.1-16.el7 for package: rpm-build-libs-4.11.1-16.el7.x86_64
---> Package rpm-libs.x86_64 0:4.11.3-32.el7 will be an update
---> Package rpm-python.x86_64 0:4.11.1-16.el7 will be updated
---> Package rpm-python.x86_64 0:4.11.3-32.el7 will be an update
--> Running transaction check
---> Package rpm-build-libs.x86_64 0:4.11.1-16.el7 will be updated
---> Package rpm-build-libs.x86_64 0:4.11.3-32.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository
Size
===============================================================================
Updating:
yum noarch 3.4.3-158.el7.centos base 1.2 M
Updating for dependencies:
python-urlgrabber noarch 3.10-8.el7 base 108 k
rpm x86_64 4.11.3-32.el7 base 1.2 M
rpm-build-libs x86_64 4.11.3-32.el7 base 105 k
rpm-libs x86_64 4.11.3-32.el7 base 276 k
rpm-python x86_64 4.11.3-32.el7 base 82 k
Transaction Summary
===============================================================================
Upgrade 1 Package (+5 Dependent packages)
Total download size: 3.0 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for base
warning: /var/cache/yum/x86_64/$releasever/base/packages/python-urlgrabber-3.10-8.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for python-urlgrabber-3.10-8.el7.noarch.rpm is not installed
(1/6): python-urlgrabber-3.10-8.el7.noarch.rpm | 108 kB 00:02
(2/6): rpm-build-libs-4.11.3-32.el7.x86_64.rpm | 105 kB 00:00
(3/6): rpm-libs-4.11.3-32.el7.x86_64.rpm | 276 kB 00:00
(4/6): rpm-python-4.11.3-32.el7.x86_64.rpm | 82 kB 00:00
(5/6): rpm-4.11.3-32.el7.x86_64.rpm | 1.2 MB 00:05
(6/6): yum-3.4.3-158.el7.centos.noarch.rpm | 1.2 MB 00:03
-------------------------------------------------------------------------------
Total 380 kB/s | 3.0 MB 00:07
Retrieving key from [http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7](http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7)
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <[[email protected]](mailto:[email protected])>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
From : [http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7](http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7)
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-0.8.9-11.el7.x86_64 has missing requires of PackageKit-backend
rhn-check-2.0.2-5.el7.noarch has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1')
Updating : rpm-4.11.3-32.el7.x86_64 1/12
Updating : rpm-libs-4.11.3-32.el7.x86_64 2/12
Updating : rpm-build-libs-4.11.3-32.el7.x86_64 3/12
Updating : rpm-python-4.11.3-32.el7.x86_64 4/12
Updating : python-urlgrabber-3.10-8.el7.noarch 5/12
Updating : yum-3.4.3-158.el7.centos.noarch 6/12
Cleanup : yum-3.4.3-132.el7.centos.0.1.noarch 7/12
Cleanup : rpm-python-4.11.1-16.el7.x86_64 8/12
Cleanup : python-urlgrabber-3.10-4.el7.noarch 9/12
Cleanup : rpm-build-libs-4.11.1-16.el7.x86_64 10/12
Cleanup : rpm-libs-4.11.1-16.el7.x86_64 11/12
Cleanup : rpm-4.11.1-16.el7.x86_64 12/12
Verifying : rpm-python-4.11.3-32.el7.x86_64 1/12
Verifying : rpm-build-libs-4.11.3-32.el7.x86_64 2/12
Verifying : yum-3.4.3-158.el7.centos.noarch 3/12
Verifying : rpm-libs-4.11.3-32.el7.x86_64 4/12
Verifying : python-urlgrabber-3.10-8.el7.noarch 5/12
Verifying : rpm-4.11.3-32.el7.x86_64 6/12
Verifying : python-urlgrabber-3.10-4.el7.noarch 7/12
Verifying : rpm-python-4.11.1-16.el7.x86_64 8/12
Verifying : rpm-libs-4.11.1-16.el7.x86_64 9/12
Verifying : rpm-build-libs-4.11.1-16.el7.x86_64 10/12
Verifying : yum-3.4.3-132.el7.centos.0.1.noarch 11/12
Verifying : rpm-4.11.1-16.el7.x86_64 12/12
Updated:
yum.noarch 0:3.4.3-158.el7.centos
Dependency Updated:
python-urlgrabber.noarch 0:3.10-8.el7 rpm.x86_64 0:4.11.3-32.el7
rpm-build-libs.x86_64 0:4.11.3-32.el7 rpm-libs.x86_64 0:4.11.3-32.el7
rpm-python.x86_64 0:4.11.3-32.el7
Complete!
[root@localhost yum.repos.d]#
再看yum版本,已经是最新版了
[root@localhost yum.repos.d]# rpm -aq | grep yum
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-updateonboot-1.1.31-34.el7.noarch
yum-utils-1.1.31-34.el7.noarch
yum-3.4.3-158.el7.centos.noarch
[root@localhost yum.repos.d]#
最后再说一下,如果使用 yum update 来更新所有软件包,最后可能会有这样两个错误:
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-0.8.9-11.el7.x86_64 has missing requires of PackageKit-backend
rhn-check-2.0.2-5.el7.noarch has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1')
其中第二个可以使用
yum install yum-rhn-plugin
来解决
我们来看一下安装tree软件
[root@localhost yum.repos.d]# yum install tree
Loaded plugins: fastestmirror, product-id, refresh-packagekit, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Unable to send message to PackageKit
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
tree x86_64 1.6.0-10.el7 base 46 k
Transaction Summary
===============================================================================
Install 1 Package
Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-0.8.9-11.el7.x86_64 has missing requires of PackageKit-backend
Installing : tree-1.6.0-10.el7.x86_64 1/1
Unable to send message to PackageKit
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
期间停止了一段时间,是被PackageKit锁定了。查了下资料,这是一个离线更新服务,基本没用,直接禁止掉。
修改这个文件:
[root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/refresh-packagekit.conf
把enable=1改成0 即可
报错: error initscripts conflicts with redhat-release-server-7.0-1.el7.x86_64
冲突导致无法更新软件,那就卸载掉冲突的软件:
rpm -e redhat-release-server-7.0-1.el7.x86_64 --nodeps
再次运行yum update,坐等更新 1054个软件包 。。。O_O