Ubuntu Server 全版本更换镜像源为阿里云镜像源

Posted opencoder

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu Server 全版本更换镜像源为阿里云镜像源相关的知识,希望对你有一定的参考价值。

查看当前 Ubuntu 镜像源

less /etc/apt/sources.list
文件部分内容:
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu focal main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu focal-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-updates main restricted

...
通过查看地址可以看到默认使用的是 Ubuntu 官方镜像源 http://cn.archive.ubuntu.com 。按 Q 键可以退出 less 模式!

备份当前镜像源

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

修改当前镜像源

vim /etc/apt/sources.list

# 打开文件不要做任何操作,直接输入 ggdG 清空文件,注意 G 是大写
ggdG
清空文件后,然后复制下镜像源(根据自己实际的版本):
  • Ubuntu 14.04 LTS
    deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
    deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
    deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
    deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
    
    deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
    deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
    
    deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
    deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
    
    ## Not recommended
    # deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
    # deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
  • ubuntu 16.04
    deb http://mirrors.aliyun.com/ubuntu/ xenial main
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
    
    deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
    
    deb http://mirrors.aliyun.com/ubuntu/ xenial universe
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
    deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
    
    deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
    deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
  • ubuntu 18.04(bionic)
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates 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
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  • ubuntu 20.04(focal)
    deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates 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
    
    deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

Esc 切换到命令模式,然后输入 wq 保存并退出。

更新镜像源

sudo apt-get update
sudo apt-get upgrade  ## optional

控制台部分输出内容:

Get:1 http://mirrors.aliyun.com/ubuntu focal InRelease [265 kB]
Get:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease [109 kB]
Get:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease [267 kB]
Get:5 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [101 kB]
Get:6 http://mirrors.aliyun.com/ubuntu focal/restricted Sources [6472 B]
Get:7 http://mirrors.aliyun.com/ubuntu focal/multiverse Sources [174 kB]
Get:8 http://mirrors.aliyun.com/ubuntu focal/main Sources [847 kB]
Get:9 http://mirrors.aliyun.com/ubuntu focal/universe Sources [9707 kB]
Get:10 http://mirrors.aliyun.com/ubuntu focal/main amd64 Packages [970 kB]
Get:11 http://mirrors.aliyun.com/ubuntu focal/main Translation-en [506 kB]
Get:12 http://mirrors.aliyun.com/ubuntu focal/main amd64 c-n-f Metadata [29.5 kB]

...

恭喜替换为阿里云镜像源成功。

参考链接:
https://blog.csdn.net/peng2hui1314/article/details/111504609

以上是关于Ubuntu Server 全版本更换镜像源为阿里云镜像源的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu20.04 LTS 更换国内163源阿里源清华源中科大源

Ubuntu更换apt源为阿里源

ubuntu docker怎么换成阿里源

Linux学习 - 02 使用 - Centos8 - 『更换rpm/epel包源为国内源』

Pycharm软件更换pip安装源为国内的清华豆瓣阿里

ubuntu20.04 LTS 更换国内163源、阿里源、清华源、中科大源