2024-09-01
Linux运维
00

目录

更换Ubuntu镜像源教程
概述
备份现有镜像源列表
修改镜像源列表
Ubuntu 16.04 (代号:xenial)
Ubuntu 18.04 (代号:bionic)
Ubuntu 20.04 (代号:focal)
Ubuntu 22.04 (代号:jammy)
Ubuntu 24.04 (代号:lunar)
更新软件包列表
常见问题及解决方法

更换Ubuntu镜像源教程

概述

本教程将介绍如何在不同版本的Ubuntu中更换为国内镜像源,以提高软件更新和安装速度。以下示例将涵盖Ubuntu 16.04、18.04、20.04、22.04、24.04五个版本。

备份现有镜像源列表

在更改镜像源之前,建议先备份当前的镜像源列表文件/etc/apt/sources.list

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

修改镜像源列表

使用文本编辑器打开/etc/apt/sources.list文件:

bash
sudo nano /etc/apt/sources.list

将文件内容替换为所需的镜像源列表。以下提供了常用的国内镜像源对应不同版本的配置。

Ubuntu 16.04 (代号:xenial)
plaintext
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ## 预发布源,不建议启用 # deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
Ubuntu 18.04 (代号:bionic)
plaintext
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse ## 预发布源,不建议启用 # deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
Ubuntu 20.04 (代号:focal)
plaintext
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security 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-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse ## 预发布源,不建议启用 # deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
Ubuntu 22.04 (代号:jammy)
plaintext
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse ## 预发布源,不建议启用 # deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
Ubuntu 24.04 (代号:lunar)
plaintext
deb http://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse ## 预发布源,不建议启用 # deb http://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse

更新软件包列表

保存并关闭/etc/apt/sources.list文件后,执行以下命令更新软件包列表:

bash
sudo apt update

等待更新完成即可。

常见问题及解决方法

  1. 更新失败或速度较慢

    • 尝试更换其他镜像源,如中科大或清华大学的镜像源。

    • 检查网络连接是否正常。

  2. 权限问题

    • 确保使用sudo命令进行操作。

    • 检查/etc/apt/sources.list文件的权限是否正确。

通过上述步骤,您可以在不同版本的Ubuntu中轻松更换为国内的镜像源,从而提升软件更新和安装的速度。

如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!