溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么安裝配置Yum

發(fā)布時(shí)間:2021-11-16 16:34:11 來(lái)源:億速云 閱讀:110 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“怎么安裝配置Yum”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

系統(tǒng)了解

查看操作系統(tǒng)詳細(xì)信息: 

lsb_release -a

查看操作系統(tǒng)發(fā)行信息: 

cat /etc/*release

查看操作系統(tǒng)位數(shù): 

getconf LONG_BIT

安裝配置Yum

在 linux 系統(tǒng)上,軟件包之間的依賴關(guān)系是一件很讓人頭疼的事情。很多工作無(wú)法實(shí)現(xiàn)可能就是因?yàn)槿鄙僖粋€(gè)軟件包,而當(dāng)你千方百計(jì)找到這個(gè)軟件包的時(shí)候,卻發(fā)現(xiàn)它跟當(dāng)前系統(tǒng)不兼容,這真是一件令人抓狂的事情。所以,我拿到蓋機(jī)器后,要做的非常重要的一件事情就是給系統(tǒng)添加軟件倉(cāng)庫(kù),以確保我能順利的安裝上大部分軟件包。

刪除系統(tǒng)自帶的 yum 服務(wù):

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

然后去鏡像網(wǎng)站下載 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

下載完成后將它們?nèi)堪惭b上:

rpm -ivh *.rpm

安裝完 yum 后,我去  163 的官方網(wǎng)站(http://mirrors.163.com/.help/centos.html?1304848825)下載了一個(gè)配置文件放到 /etc/yum.repos.d 目錄下,然后運(yùn)行以下命令,以清除緩存并下載新的鏡像緩存:

yum clean all
yum makecache

問(wèn)題出現(xiàn)了,運(yùn)行 yum makecache 時(shí)提示鏡像地址不對(duì)。我手動(dòng)打開(kāi)該地址,發(fā)現(xiàn)該地址確實(shí)不存在。然后我將鏡像地址的目錄一級(jí)一級(jí)的向前退,終于發(fā)現(xiàn)了一個(gè) readme 文件,該文件內(nèi)容如下:

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

原來(lái)是地址發(fā)生了變化,按照提示,在瀏覽器中找到了對(duì)應(yīng)的鏡像地址,于是修改配置文件:

gedit /etc/yum.repos.d/CentOS5-Base-163.repo

配置文件內(nèi)容如下:

# 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

保存后再次執(zhí)行以下命令:

yum clean all
yum makecache

到此,添加軟件倉(cāng)庫(kù)成功。

安裝第三方軟件倉(cāng)庫(kù)

添加完 163 的軟件倉(cāng)庫(kù)后,首先嘗試安裝了 git,發(fā)現(xiàn)倉(cāng)庫(kù)里邊竟然沒(méi)有 git。不得不說(shuō) Redhat 系統(tǒng)是比較穩(wěn)定的,但是安裝一個(gè)軟件實(shí)在是太麻煩了,這也是我在個(gè)人電腦上不使用它的原因。沒(méi)辦法,添加第三方軟件倉(cāng)庫(kù)試試吧。 

安裝 yum-priorities 插件

yum-priorities 插件是用來(lái)設(shè)置yum在調(diào)用軟件源時(shí)的順序的。因?yàn)楣俜教峁┑能浖矗际潜容^穩(wěn)定和被推薦使用的。因此,官方源的順序要高于第三方源的順序。如何保證這個(gè)順序,就需要安裝yum-priorities這插件了: 

yum install yum-priorities

安裝完后需要設(shè)置/etc/yum.repos.d/ 目錄下的.repo相關(guān)文件(如CentOS-Base.repo),在這些文件中插入順序指令:priority=N (N為1到99的正整數(shù),數(shù)值越小越優(yōu)先),例如:

[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 軟件倉(cāng)庫(kù)

epel 是 yum 的一個(gè)軟件源,里面包含了許多基本源里沒(méi)有的軟件,安裝 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 軟件倉(cāng)庫(kù)

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 軟件倉(cāng)庫(kù):

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,以修改軟件倉(cāng)庫(kù)的加載順序。

增強(qiáng) shell 的自動(dòng)補(bǔ)全功能

在 Linux 下的工作大部分都是用命令來(lái)完成,而我總是懶得去那些繁復(fù)的命令,即使記憶再好,我想也記不住全部的命令。所以 Linux Shell 的 Tab 補(bǔ)全功能變得尤其重要。通常情況下, Shell 自帶的補(bǔ)全功能只能補(bǔ)全系統(tǒng)中簡(jiǎn)單的命令。要增強(qiáng) shell 的補(bǔ)全功能,需要安裝一個(gè) bash-completion: 

yum install -y bash-completion

安裝完成之后執(zhí)行以下命令: 

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

這樣,在你輸入 yum install lib 之后,再按 Tab 鍵,便會(huì)列出所有的可安裝的軟件包。bash-completion 的補(bǔ)全功能是通過(guò)配置文件實(shí)現(xiàn)的,配置文件放在 /etc/bash_completion.d/ 下。如果發(fā)現(xiàn)有軟件工具無(wú)法自動(dòng)補(bǔ)全,可以安裝相應(yīng)的配置文件試試。 

“怎么安裝配置Yum”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

yum
AI