centos 使用yum 安裝出現 File contains no section headers 錯誤解決方法


安裝好CenOS7后,自帶的yum不能直接使用,使用會出現如下問題:



 

原因是沒有配置yum源,修改/etc/yum.repos.d/CenOS-Base.repo文件內容如下:

C代碼   收藏代碼
  1. # CentOS-Base.repo  
  2. #  
  3. # The mirror system uses the connecting IP address of the client and the  
  4. # update status of each mirror to pick mirrors that are updated to and  
  5. # geographically close to the client.  You should use this for CentOS updates  
  6. # unless you are manually picking other mirrors.  
  7. #  
  8. # If the mirrorlist= does not work for you, as a fall back you can try the   
  9. # remarked out baseurl= line instead.  
  10. #  
  11. #  
  12.   
  13. [base]  
  14. name=CentOS-$releasever - Base  
  15. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra  
  16. #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/  
  17. gpgcheck=1  
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  19.   
  20. #released updates   
  21. [updates]  
  22. name=CentOS-$releasever - Updates  
  23. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra  
  24. #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/  
  25. gpgcheck=1  
  26. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  27.   
  28. #additional packages that may be useful  
  29. [extras]  
  30. name=CentOS-$releasever - Extras  
  31. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra  
  32. #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/  
  33. gpgcheck=1  
  34. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  35.   
  36. #additional packages that extend functionality of existing packages  
  37. [centosplus]  
  38. name=CentOS-$releasever - Plus  
  39. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra  
  40. #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/  
  41. gpgcheck=1  
  42. enabled=0  
  43. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  

 編輯命令如下:

C代碼   收藏代碼
  1. vi /etc/yum.repos.d/CentOS-Base.repo  

 保存命令

     

    按ESC鍵 跳到命令模式,然后:

     

    :w   保存文件但不退出vi

    :w file 將修改另外保存到file中,不退出vi

    :w!   強制保存,不推出vi

    :wq  保存文件並退出vi

    :wq! 強制保存文件,並退出vi

    q:  不保存文件,退出vi

    :q! 不保存文件,強制退出vi

    :e! 放棄所有修改,從上次保存文件開始再編輯

 

或者先刪除原有的文件

C代碼   收藏代碼
  1. rm -f  /etc/yum.repos.d/CentOS-Base.repo  

然后重新下載阿里的

C代碼   收藏代碼
  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  

  清理緩存

C代碼   收藏代碼
  1. yum clean all  

 

ps:如果上述方法沒有解決,嘗試下面:

 

刪除yum.repos.d目錄下所有文件

C代碼   收藏代碼
  1. rm -f /etc/yum.repos.d/*  

 然后重新下載阿里的

 

C代碼   收藏代碼
  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  

 

清理緩存

C代碼   收藏代碼
  1. yum clean all  

 

測試下載安裝

C代碼   收藏代碼
  1. yum install gcc  

 

 

結果如下:



 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM