当前位置: 代码网 > it编程>数据库>Mysql > Ubuntu24.04配置国内源的操作步骤

Ubuntu24.04配置国内源的操作步骤

2025年07月02日 Mysql 我要评论
配置国内镜像源为什么需要配置国内镜像源?ubuntu 默认使用官方源服务器(通常位于海外),在国内访问时会遇到以下问题:下载速度极慢,经常只有几kb/s网络连接不稳定,容易中断高峰时段访问困难影响系统

配置国内镜像源

为什么需要配置国内镜像源?

ubuntu 默认使用官方源服务器(通常位于海外),在国内访问时会遇到以下问题:

  • 下载速度极慢,经常只有几kb/s
  • 网络连接不稳定,容易中断
  • 高峰时段访问困难
  • 影响系统更新和软件安装效率

配置国内镜像源后,大幅改善使用体验。

常见的国内镜像源

国内主要的ubuntu镜像源包括:

本指南以阿里云镜像为例

操作步骤

一、备份原有源列表

修改任何系统配置文件之前,备份是必不可少的步骤!  这是系统管理的基本原则。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

备份完成后,可以通过以下命令验证备份文件:

ls -la /etc/apt/sources.list*

如果出现问题,可以随时恢复:

sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list

二、查看当前系统版本

确认系统版本信息,确保使用正确的源配置:

lsb_release -a
cat /etc/os-release

ubuntu 24.04的代号是"noble",这在配置源时很重要。

三、更换为阿里云镜像源

方法一:使用sed命令批量替换

sudo sed -i 's|http://.*archive.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list
sudo sed -i 's|http://.*security.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list

方法二:直接重写整个文件(推荐)

sudo tee /etc/apt/sources.list <<-'eof'
# 阿里云 ubuntu 24.04 lts 镜像源
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

# 源码包(可选,一般用户不需要)
# deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
eof

软件仓库组件说明

  • main:官方支持的自由软件
  • restricted:官方支持的非完全自由软件
  • universe:社区维护的自由软件
  • multiverse:非自由软件

四、更新软件包缓存

sudo apt update
sudo apt upgrade -y

更新过程中如果看到类似以下输出,说明配置成功:

get:1 https://mirrors.aliyun.com/ubuntu noble inrelease [256 kb]
get:2 https://mirrors.aliyun.com/ubuntu noble-updates inrelease [126 kb]

五、验证源配置

检查下载速度是否有明显提升:

sudo apt install htop

如果安装速度明显变快,说明配置成功。

到此这篇关于ubuntu24.04配置国内源的操作步骤的文章就介绍到这了,更多相关ubuntu24.04配置国内源内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com