温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么安装配置Yum

发布时间:2021-11-16 16:34:11 来源:亿速云 阅读:96 作者:iii 栏目:大数据

本篇内容介绍了“怎么安装配置Yum”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

系统了解

查看操作系统详细信息: 

lsb_release -a

查看操作系统发行信息: 

cat /etc/*release

查看操作系统位数: 

getconf LONG_BIT

安装配置Yum

在 linux 系统上,软件包之间的依赖关系是一件很让人头疼的事情。很多工作无法实现可能就是因为缺少一个软件包,而当你千方百计找到这个软件包的时候,却发现它跟当前系统不兼容,这真是一件令人抓狂的事情。所以,我拿到盖机器后,要做的非常重要的一件事情就是给系统添加软件仓库,以确保我能顺利的安装上大部分软件包。

删除系统自带的 yum 服务:

rpm -qa | grep yum | xargs rpm -e --nodeps

然后去镜像网站下载 yum 的安装包重新安装。我选择的是 163 的镜像(http://mirrors.163.com/centos/),然后下载下列软件包: 

wget http://mirrors.163.com/centos/5/os/i386/CentOS/yum-3.2.22-40.el5.centos.noarch.rpm
wget http://mirrors.163.com/centos/5/os/i386/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
wget http://mirrors.163.com/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-4.el5.i386.rpm

下载完成后将它们全部安装上:

rpm -ivh *.rpm

安装完 yum 后,我去  163 的官方网站(http://mirrors.163.com/.help/centos.html?1304848825)下载了一个配置文件放到 /etc/yum.repos.d 目录下,然后运行以下命令,以清除缓存并下载新的镜像缓存:

yum clean all
yum makecache

问题出现了,运行 yum makecache 时提示镜像地址不对。我手动打开该地址,发现该地址确实不存在。然后我将镜像地址的目录一级一级的向前退,终于发现了一个 readme 文件,该文件内容如下:

wget This directory (and version of CentOS) is deprecated.  For normal users,
you should use /5/ and not /5.6/ in your path. Please see this FAQ
concerning the CentOS release scheme:

https://wiki.centos.org/FAQ/General

If you know what you are doing, and absolutely want to remain at the 5.6
level, go to http://vault.centos.org/ for packages. Please keep in mind that 5.6 no longer gets any updates

原来是地址发生了变化,按照提示,在浏览器中找到了对应的镜像地址,于是修改配置文件:

gedit /etc/yum.repos.d/CentOS5-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-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/5/os/i386/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/5/os/i386/RPM-GPG-KEY-CentOS-5


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

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

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

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

保存后再次执行以下命令:

yum clean all
yum makecache

到此,添加软件仓库成功。

安装第三方软件仓库

添加完 163 的软件仓库后,首先尝试安装了 git,发现仓库里边竟然没有 git。不得不说 Redhat 系统是比较稳定的,但是安装一个软件实在是太麻烦了,这也是我在个人电脑上不使用它的原因。没办法,添加第三方软件仓库试试吧。 

安装 yum-priorities 插件

yum-priorities 插件是用来设置yum在调用软件源时的顺序的。因为官方提供的软件源,都是比较稳定和被推荐使用的。因此,官方源的顺序要高于第三方源的顺序。如何保证这个顺序,就需要安装yum-priorities这插件了: 

yum install yum-priorities

安装完后需要设置/etc/yum.repos.d/ 目录下的.repo相关文件(如CentOS-Base.repo),在这些文件中插入顺序指令:priority=N (N为1到99的正整数,数值越小越优先),例如:

[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
priority=2

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
priority=2

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
priority=2

添加 epel 软件仓库

epel 是 yum 的一个软件源,里面包含了许多基本源里没有的软件,安装 epel 源命令如下: 

wget http://mirrors.yun-idc.com/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -ivh epel-release-5-4.noarch.rpm
yum clean all
yum makecache

再次尝试安装 git,成功了。

添加 rpmforge 软件仓库

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.i386.rpm
rpm -ivh rpmforge-release-0.5.3-1.el5.rf.i386.rpm
yum clean all
yum makecache

添加 rpmfusion 软件仓库:

wget http://download1.rpmfusion.org/free/el/updates/5/i386/rpmfusion-free-release-5-1.noarch.rpm
wget http://download1.rpmfusion.org/nonfree/el/updates/5/i386/rpmfusion-nonfree-release-5-1.noarch.rpm

下载完成之后同上安装即可。安装完后记得在配置文件中修改 priority=N,以修改软件仓库的加载顺序。

增强 shell 的自动补全功能

在 Linux 下的工作大部分都是用命令来完成,而我总是懒得去那些繁复的命令,即使记忆再好,我想也记不住全部的命令。所以 Linux Shell 的 Tab 补全功能变得尤其重要。通常情况下, Shell 自带的补全功能只能补全系统中简单的命令。要增强 shell 的补全功能,需要安装一个 bash-completion: 

yum install -y bash-completion

安装完成之后执行以下命令: 

echo '. /etc/bash_completion' >> /etc/bashrc
source /etc/bashrc

这样,在你输入 yum install lib 之后,再按 Tab 键,便会列出所有的可安装的软件包。bash-completion 的补全功能是通过配置文件实现的,配置文件放在 /etc/bash_completion.d/ 下。如果发现有软件工具无法自动补全,可以安装相应的配置文件试试。 

“怎么安装配置Yum”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

yum
AI