Try   HackMD

Centos7 reinstall Yum

tags: 系統
本次centos 7 版本為 centos7.6.18

不小心將python 刪除 導致 yum 無法使用
Referance centos/packages/repository

1. 刪除所有python & yum 檔案

1.1 Pyhton

  • 強制刪除已安裝python 及關連檔案
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
  • 刪除所有殘留檔案
whereis python |xargs rm -frv -rf

1.2 yum

  • 強制刪除已安裝python 及關連檔案
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
  • 刪除所有殘留檔案
whereis yum |xargs rm -frv -rf

2. Download package

http://mirrors.163.com/centos/7/os/x86_64/Packages/ 下載需求套件 (請依網站最新版本為準)

python-2.7.5-68.el7.x86_64.rpm
python-devel-2.7.5-68.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm
python-libs-2.7.5-68.el7.x86_64.rpm
python-pycurl-7.19.0-19.el7.x86_64.rpm
python-setuptools-0.9.8-7.el7.noarch.rpm
python-urlgrabber-3.10-8.el7.noarch.rpm
rpm-python-4.11.3-32.el7.x86_64.rpm
yum-3.4.3-158.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-aliases-1.1.31-45.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
yum-plugin-protectbase-1.1.31-45.el7.noarch.rpm
yum-utils-1.1.31-45.el7.noarch.rpm

3. 修改檔案名稱

mv python-setuptools-0.9.8-7.el7.noarch.rpm python-setuptools-0.9.8-7.el7.noarch
mv yum-utils-1.1.31-45.el7.noarch.rpm yum-utils-1.1.31-45.el7.noarch
mv yum-plugin-aliases-1.1.31-45.el7.noarch.rpm yum-plugin-aliases-1.1.31-45.el7.noarch

4. 安裝

rpm -Uvh --replacepkgs python*.rpm
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm

  • 如一直報錯
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    ,確認無缺少檔案時使用rpm -ivh --force --nodeps rpm-python*.rpm yum*.rpm

5. 測試

  • Python
    python --version
  • yum
    yum --version
  • update yum
    yum update -y