本教程将介绍如何在不同版本的Ubuntu中更换为国内镜像源,以提高软件更新和安装速度。以下示例将涵盖Ubuntu 16.04、18.04、20.04、22.04、24.04五个版本。
在更改镜像源之前,建议先备份当前的镜像源列表文件/etc/apt/sources.list
。
bashsudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
使用文本编辑器打开/etc/apt/sources.list
文件:
bashsudo nano /etc/apt/sources.list
将文件内容替换为所需的镜像源列表。以下提供了常用的国内镜像源对应不同版本的配置。
plaintextdeb 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
plaintextdeb 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
plaintextdeb 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
plaintextdeb 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
plaintextdeb 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
文件后,执行以下命令更新软件包列表:
bashsudo apt update
等待更新完成即可。
更新失败或速度较慢:
尝试更换其他镜像源,如中科大或清华大学的镜像源。
检查网络连接是否正常。
权限问题:
确保使用sudo
命令进行操作。
检查/etc/apt/sources.list
文件的权限是否正确。
通过上述步骤,您可以在不同版本的Ubuntu中轻松更换为国内的镜像源,从而提升软件更新和安装的速度。
本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!