更换软件源为国内镜像可提升Linux系统下载速度。首先备份原配置,再修改Ubuntu的/etc/apt/sources.list或CentOS的.repo文件,替换为清华、阿里云等国内镜像源,保存后更新软件包索引。也可使用一键脚本自动更换。最后通过查看仓库列表和测试安装软件验证更换结果。

如果您在使用Linux系统时发现软件包下载速度缓慢,这通常是因为默认的软件源位于海外,网络延迟较高。将软件源更换为国内镜像站可以显著提升下载速度和系统更新效率。
本文运行环境:华为MateStation B515,Ubuntu 24.04
Ubuntu及其衍生版使用APT作为包管理工具,通过修改/etc/apt/sources.list文件可切换软件源。操作前备份原文件可防止配置错误导致无法安装软件。
1、打开终端执行命令备份原始源列表:sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak。
2、使用文本编辑器打开源配置文件:sudo nano /etc/apt/sources.list。
3、删除文件内所有内容,根据系统版本添加以下任一镜像源地址:
清华大学开源软件镜像站源(推荐):
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
4、保存文件并退出编辑器,执行命令更新软件包索引:sudo apt update。
CentOS 8及以上版本使用DNF作为默认包管理器,旧版本使用YUM。更换镜像源需替换/etc/yum.repos.d/目录下的.repo文件,以启用国内镜像站点的软件仓库。
1、备份原有仓库配置文件:sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak。
2、根据CentOS版本下载对应的国内镜像源配置文件:
若使用CentOS 7,执行:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo。
若使用CentOS Stream 8,执行:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/vault/CentOS-Base.repo。
3、清除旧缓存并生成新缓存:
对于CentOS 7:
sudo yum clean all && sudo yum makecache。
对于CentOS 8及以上:
sudo dnf clean all && sudo dnf makecache。
部分第三方维护的一键脚本可自动检测系统类型并更换为最优国内镜像源,适用于不熟悉命令行操作的用户,能减少手动编辑配置出错的概率。
1、从可信渠道获取一键换源脚本,例如执行:wget https://mirror-script.example.com/switch-mirror.sh(请替换为实际可用脚本地址)。
2、赋予脚本可执行权限:chmod +x switch-mirror.sh。
3、以管理员权限运行脚本:sudo ./switch-mirror.sh,脚本将自动完成备份、替换和缓存更新操作。
确认软件源已成功更换并正常工作,可通过检查当前启用的仓库列表和测试软件包下载来验证,避免因配置错误导致后续无法安装软件。
1、查看当前软件仓库状态:
Ubuntu系统执行:apt list --upgradable,观察输出中的源地址是否为国内镜像站域名。
CentOS系统执行:dnf repolist 或 yum repolist,检查Repo URL列是否显示阿里云、清华等国内镜像地址。
2、尝试安装一个轻量级软件包进行测试,如:sudo apt install cowsay 或 sudo dnf install neofetch,观察下载速度是否明显提升。
以上就是LINUX怎么更换软件源_LINUX更换国内镜像源提升下载速度的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号