centos 使用yum安装python3报错+更换yum国内源解决

谁践踏了优雅 2022-12-17 14:59 523阅读 0赞

文章目录

    • 一、问题由来:
    • 二、步骤:
      • 1、访问清华镜像源:
      • 2、点击问号帮助:
      • 3、建议先备份 CentOS-Base.repo
      • 4、更改:/etc/yum.repos.d/CentOS-Base.repo
      • 5、最后,更新软件包缓存
      • 6、安装python3

一、问题由来:

今天购买了一台vps测试学习下,结果使用yum命令安装python3,给我一堆错误,然后刚开始以为没有网络,使用curl访问百度什么都没有问题。然后觉得是yum源 的问题。所以百度搜索了下配置yum源。

最后问题解决,整理下这个文章,方便下次再遇到可以快速解决。

二、步骤:

1、访问清华镜像源:

清华镜像源

2、点击问号帮助:

在这里插入图片描述

进入官方帮助页面:

3、建议先备份 CentOS-Base.repo

  1. sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

4、更改:/etc/yum.repos.d/CentOS-Base.repo

编辑/etc/yum.repos.d/CentOS-Base.repo

  1. vi /etc/yum.repos.d/CentOS-Base.repo

将所有的mirrorlist这一行注销,将所有的baseurl改为清华镜像地址,保存即可

  1. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
  2. baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/

将里面的两行改为我的这种:
在这里插入图片描述

或者直接复制官方的(全文替换,我的正好是centos7,可以全文替换,不是7版本的系统,还是,一个一个替换吧):

  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. [base]
  13. name=CentOS-$releasever - Base
  14. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
  15. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
  16. enabled=1
  17. gpgcheck=1
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
  19. #released updates
  20. [updates]
  21. name=CentOS-$releasever - Updates
  22. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
  23. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
  24. enabled=1
  25. gpgcheck=1
  26. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
  27. #additional packages that may be useful
  28. [extras]
  29. name=CentOS-$releasever - Extras
  30. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
  31. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
  32. enabled=1
  33. gpgcheck=1
  34. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
  35. #additional packages that extend functionality of existing packages
  36. [centosplus]
  37. name=CentOS-$releasever - Plus
  38. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
  39. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
  40. gpgcheck=1
  41. enabled=0
  42. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

5、最后,更新软件包缓存

  1. sudo yum makecache

在这里插入图片描述

6、安装python3

  1. yum install python3

在这里插入图片描述

参考文章:
https://mirrors.cnnic.cn/help/centos/
https://blog.csdn.net/xiaojin21cen/article/details/84726193

发表评论

表情:
评论列表 (有 0 条评论,523人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Centos7 更换yum

    背景   Centos 7默认的yum源网络不好使,所以更改yum源为阿里云 解决方案          命令,可选两种方式均可以,此种命令更换源为阿里云    一

    相关 Centos配置国内yum

    网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错,将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本

    相关 Centos配置国内yum

    网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错,将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本