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

【注】系统环境是 Ubuntu Server 20.04 LTS ,此外还测试了 Ubuntu Server 18.04 ,其他版本也是可以通用的,只是添加的源不同。

参考链接:

1. 查看当前 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 。

2. 备份当前镜像源

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

3. 修改当前镜像源

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 保存并退出。

4. 更新镜像源

sudo apt-get update

控制台部分输出内容:

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]

...

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

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注