Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

RedHat 安裝 yum 完整步驟:從源碼 RPM 重建安裝與配置更新源

編輯:關於 Linux

RedHat 系統若未預裝 yum,可從官方源碼 RPM 重建安裝,並配置 CentOS 鏡像源作為更新來源。本文記錄下載源碼 RPM、rpmbuild 重建、安裝、配置 /etc/yum.repos.d/ 源檔案、執行 yum update 的完整流程。

1. 下載 yum 源碼 RPM

wget https://yum.baseurl.org/download/2.0/yum-2.0.8-1.src.rpm
# 可選擇其他版本:https://yum.baseurl.org/download/2.0/

2. 重建並安裝

rpmbuild --rebuild yum-2.0.8-1.src.rpm
cd /usr/src/redhat/RPMS/noarch/
rpm -ivh yum-2.0.8-1.noarch.rpm
# 若報錯依賴問題:
rpm -ivh --nodeps --replacefiles --force *.rpm

3. 配置 yum 更新源 (CentOS 鏡像)

vi /etc/yum.repos.d/CentOS-Base.repo
# 內容:
[base]
name=CentOS-$releasever - Base
baseurl=https://centos.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-$releasever

[updates]
name=CentOS-$releasever - Updates
baseurl=https://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-$releasever

[extras]
name=CentOS-$releasever - Extras
baseurl=https://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=https://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-$releasever

4. 更新 yum 快取並測試

yum clean all
yum makecache
yum update
# 等待完成即可正常使用 yum install 套件名

yum 安裝配置截圖

補充:其他套件管理方式對照

方式適用系統安裝指令移除指令
yumCentOS, RedHat, Fedorayum install pkgyum remove pkg
apt-getUbuntu, Debianapt-get install pkgapt-get autoremove pkg
pkg_addFreeBSD (pkg)pkg_add pkg.tgzpkg_delete pkg
portsFreeBSDcd /usr/ports/... && make installmake deinstall
源碼編譯通用./configure && make && make installmake uninstall (需源碼目錄)

注意事項

  • RedHat 官方建議使用 dnf(RHEL 8+)或向 RedHat 訂閱官方倉庫。
  • 使用 CentOS 鏡像源屬非官方支援,生產環境請評估合規性。
  • rpmbuild --rebuild 需安裝 rpm-build、gcc 等建構工具。
Copyright © Windows教程網 All Rights Reserved