linux系统怎么换源
linux系统怎么换源详细介绍
在 Linux 系统中更换软件源(镜像源)可以提高软件下载和更新速度,以下是常见的操作步骤,适用于不同的 Linux 发行版:
一、Debian/Ubuntu 系列(如 Debian、Ubuntu、Linux Mint 等)
1.
备份原源文件(重要)
bash
/etc/apt/sources.list /etc/apt/sources.list.bak
2.
编辑源文件
bash
/etc/apt/sources.list
3.
替换为国内镜像源(以阿里云为例)
plaintext
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
4.
更新软件源列表
bash
update
二、RedHat/CentOS 系列(如 CentOS、RHEL、Rocky Linux 等)
1.
备份原源文件
bash
/etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2.
下载并替换为国内镜像源(以阿里云为例)
bash
/etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
3.
生成缓存
bash
yum makecache
三、其他通用说明
- 常用国内镜像源
- 阿里云:https://mirrors.aliyun.com
- 清华大学:https://mirrors.tuna.tsinghua.edu.cn
- 中科大:https://mirrors.ustc.edu.cn
- 图形化工具(部分发行版适用)
- Ubuntu:进入 系统设置 > 软件和更新,选择国内镜像源。
- CentOS:使用
yum-config-manager工具或图形化软件中心配置。
- Arch Linux
编辑/etc/pacman.d/mirrorlist,将国内镜像移到文件顶部:
bash/etc/pacman.d/mirrorlist
四、注意事项
- 更换源后若出现依赖问题,可恢复备份的源文件(如
sources.list.bak或CentOS-Base.repo.bak)。 - 不同 Linux 版本(如 Ubuntu 的
focal、CentOS 的8.5)需匹配对应的镜像源版本号,否则可能导致错误。
通过以上步骤,即可完成 Linux 系统的软件源更换,提升软件安装和更新效率。