ASCII码 ASCII码

Linux环境更换阿里源(CentOS+Ubuntu)

发布于:2022-06-26 13:29:05  栏目:技术文档

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站

CentOS

1.备份原来的源

在控制台输入mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup备份原本的源

2、下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

3、非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用,可以修改配置

  1. sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

4、生成缓存

  1. yum makecache

5、查看当前源

  1. yum repolist

Ubuntu

1.备份原来的源

在控制台输入sudo cp /etc/apt/sources.list /etc/apt/source.list.bk备份原本的源

2.修改源

  • 在控制台输入sudo vim /etc/apt/source.list会进入文件
  • 按O即可进行插入代码,首先先将文件内的每行前面都加上#
  • 接着在尾部粘贴如下代码
  1. deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  2. deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  4. deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  6. deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  7. deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  9. deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

file

  • 按Esc可以退出插入状态,接着按出 :wq 则会在左下角出现字符,按回车则保存成功

更新源配置及系统

  • 在控制台输入

sudo apt-get updatesudo apt-get upgrade

  • 接着按回车即可进行更新
  • 过程中出现此类网址则更换源成功

file

原文链接:https://juejin.cn/post/7111738157388791822

相关推荐
阅读 +