在配置yum前首先得说说rpm,在redhat和centos linux系统上,rpm作为软件包管理工具,可以方便的安装、查询、卸载软件包。常见命令如下:
rpm -ivh jdk-7u25-linux-x64.rpm
rpm -e jdk-7u25-linux-x64.rpm
rpm -Uvh jdk-7u25-linux-x64.rpm
rpm -ql yum-3.4.3-118.el7.noarch
rpm -qa
rpm -qf /var/lib/yum/yumdb
但是在多个包组成的rpm包用rpm命令安装时,其依赖包问题是超级繁琐的。
yum是redhat和centos的软件包管理工具,安装软件包时可以在网上远程仓库或者本地自动下载所有依赖包,解决了rpm的痛点。今天主要学习下远程yum源配置。由于redhat 自带的 yum 源是需要注册收费才能更新下载软件的,如果没有注册就使用,则会报下面的错误:
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
所以我们需要把yum源修改为centos的源。
查看自带yum:
rpm -qa | grep yum
卸载自带yum:
rpm -qa | grep yum | xargs rpm -e --nodeps
查看系统版本:
cat /etc/redhat-release
下载安装软件包:
http://mirrors.163.com/centos/7/os/x86_64/Packages/
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-3.4.3-158.el7.centos.noarch.rpm
yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
执行以下安装命令报错,依赖包的版本不符:
rpm -ivh yum*
这里升级python-urlgrabber和rpm包版本:
rpm-4.11.3-32.el7.x86_64.rpm
python-urlgrabber-3.10-8.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-32.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
rpm -Uvh rpm-4.11.3-32.el7.x86_64.rpm --nodeps
rpm -Uvh python-urlgrabber-3.10-8.el7.noarch.rpm --nodeps
然后安装:
新建配置文件:
vim /etc/yum.repos.d/CentOS-Base.repo
加入以下配置:
[base]
name=CentOS-$7 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$7 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$7 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
然后清理缓存:
yum clean all
生成缓存:
yum makecache
测试源:
yum update -y
可以看到已经可以通过yum安装相关软件包更新。
原作者:小碗汤
|