返回列表 发布新帖
查看: 10|回复: 0

更换 Linux 系统为阿里云镜像源详解

发表于 昨天 16:37 | 查看全部 |阅读模式

这里或许是互联网从业者的最后一片净土,随客社区期待您的加入!

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在使用 Linux 系统时,默认的软件源可能存在下载速度慢、不稳定或软件版本不够新等问题。为了解决这些问题,国内用户通常会将软件源更换为更快的镜像站,比如阿里云提供的开源镜像服务。本文将分别介绍如何在 CentOS 和 Ubuntu 系统中,将软件源更换为阿里云源,以提升软件包安装与更新的速度与效率。
一、CentOS 更换阿里云镜像源
1. 查看系统版本
先确认当前的 CentOS 版本:
  1. cat /etc/redhat-release
复制代码
例如返回结果为:CentOS Linux release 7.9.2009 (Core),则版本为 7。
2. 备份原有源配置
  1. cd /etc/yum.repos.d/
复制代码
  1. mkdir backup
复制代码
  1. mv *.repo backup/
复制代码
3. 下载阿里云 YUM 源配置文件
以 CentOS 7 为例:
  1. curl -o CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
复制代码
如果是 CentOS 8:
  1. curl -o CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
复制代码
4. 生成缓存
  1. yum clean all
复制代码
  1. yum makecache
复制代码
现在,你的 CentOS 系统已使用阿里云 YUM 源。
二、Ubuntu 更换阿里云镜像源
1. 查看系统版本
  1. lsb_release -a
复制代码
例如返回:
Distributor ID: Ubuntu  
Description:    Ubuntu 20.04.6 LTS  
Release:        20.04  
Codename:       focal
说明当前版本为 Ubuntu 20.04,代号为 focal。
2. 备份原有源配置
  1. sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
复制代码
3. 修改 sources.list
可以手动编辑:
  1. sudo nano /etc/apt/sources.list
复制代码
将内容替换为:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

或者使用命令直接替换:
sudo bash -c 'cat > /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
EOF'
将 focal 替换为你当前系统对应的代号(如 bionic, jammy 等)。
4. 更新软件包索引
  1. sudo apt update
复制代码
至此,Ubuntu 系统已经切换至阿里云源。
三、验证镜像是否生效
安装任意软件测试即可,比如安装 htop:
# CentOS
  1. yum install -y htop
复制代码
# Ubuntu
  1. sudo apt install -y htop
复制代码
如果下载速度明显提升,即表示已成功切换为阿里云镜像源。
四、注意事项
  • 阿里云源为中国大陆用户优化,国外用户建议使用其他 CDN 镜像。
  • 更换源前建议备份原始配置,防止配置错误导致系统无法更新。
  • 若使用了 proxy、VPN,可能会影响镜像源访问速度。
  • 部分特殊软件库(如 EPEL、Docker、Node.js)需要单独添加。
五、总结
阿里云提供了稳定且高速的软件源服务,适合国内用户使用。通过将 Linux 系统的软件源更换为阿里云镜像,可以大大提高系统安装和更新软件包的效率,是运维人员或开发者提升系统部署效率的一个重要操作步骤。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2001-2025 Suike Tech All Rights Reserved. 随客交流社区 (备案号:津ICP备19010126号) |Processed in 0.112578 second(s), 6 queries , Gzip On, MemCached On.
关灯 在本版发帖返回顶部
快速回复 返回顶部 返回列表