Ubuntu 24.04 更换国内软件源(以阿里云为例)

方法一:一键脚本配置

bash 复制代码
#!/bin/bash

# 备份原有配置
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup.$(date +%Y%m%d%H%M%S)

# 写入阿里云源配置
sudo tee /etc/apt/sources.list << 'EOF'
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
EOF

# 更新缓存
sudo apt update
sudo apt upgrade -y

方法二:命令行配置

第1步:备份原有源配置
bash 复制代码
# 备份原有源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
第2步:编辑软件源列表
bash 复制代码
# 使用vi编辑器打开源列表文件
sudo vi /etc/apt/sources.list
第3步:替换为阿里云源

将文件内容替换为以下内容:

bash 复制代码
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
# deb-src 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-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
第4步:更新软件包列表
bash 复制代码
# 更新软件包列表
sudo apt update

# 升级已安装的软件包(可选)
sudo apt upgrade

其他国内镜像源选择

如果您想使用其他镜像源,只需将上述配置中的 mirrors.aliyun.com 替换为:

  • 腾讯云 : mirrors.cloud.tencent.com
  • 华为云 : repo.huaweicloud.com
  • 清华源 : mirrors.tuna.tsinghua.edu.cn
  • 中科大源 : mirrors.ustc.edu.cn

验证配置是否成功

bash 复制代码
# 检查源是否正常
sudo apt update

# 查看当前使用的源
sudo apt policy

# 测试安装软件包
sudo apt install htop

注意事项

  1. 版本对应 : Ubuntu 24.04 的代号是 "Noble Numbat",在源配置中对应 noble

  2. 网络连接: 确保服务器可以正常访问互联网

  3. 安全性 : 建议使用https协议的镜像源,如 https://mirrors.aliyun.com

  4. 恢复原配置: 如果出现问题,可以恢复备份:

    bash 复制代码
    sudo cp /etc/apt/sources.list.backup /etc/apt/sources.list
    sudo apt update

国内常用镜像源地址

提供商 主地址 备注
阿里云 https://mirrors.aliyun.com/ubuntu/ 速度快,覆盖广
腾讯云 https://mirrors.cloud.tencent.com/ubuntu/ 腾讯云用户推荐
华为云 https://repo.huaweicloud.com/ubuntu/ 华为云用户推荐
清华源 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ 教育网推荐

完成以上步骤后,您的Ubuntu 24.04系统就会使用国内的镜像源,软件下载速度将得到显著提升。

相关推荐
松涛和鸣8 小时前
72、IMX6ULL驱动实战:设备树(DTS/DTB)+ GPIO子系统+Platform总线
linux·服务器·arm开发·数据库·单片机
Anesthesia丶8 小时前
Ubuntu20.04 升级 Ubuntu24.04 LTS
ubuntu
简单中的复杂8 小时前
【避坑指南】RK3576 Linux SDK 编译:解决 Buildroot 卡死在 host-gcc-final 的终极方案
linux·嵌入式硬件
wVelpro8 小时前
如何在Pycharm 2025.3 版本实现虚拟环境“Make available to all projects”
linux·ide·pycharm
程序员老舅9 小时前
C++高并发精髓:无锁队列深度解析
linux·c++·内存管理·c/c++·原子操作·无锁队列
雨中风华9 小时前
Linux, macOS系统实现远程目录访问(等同于windows平台xFsRedir软件的目录重定向)
linux·windows·macos
爱吃生蚝的于勒10 小时前
【Linux】进程信号之捕捉(三)
linux·运维·服务器·c语言·数据结构·c++·学习
The森10 小时前
Linux IO 模型纵深解析 01:从 Unix 传统到 Linux 内核的 IO 第一性原理
linux·服务器·c语言·经验分享·笔记·unix
翼龙云_cloud10 小时前
腾讯云代理商: Linux 云服务器搭建 FTP 服务指南
linux·服务器·腾讯云
纤纡.10 小时前
Linux中SQL 从基础到进阶:五大分类详解与表结构操作(ALTER/DROP)全攻略
linux·数据库·sql