将 Ubuntu 默认源修改为国内源

Ubuntu默认源在国外,可以将默认源修改为国内的阿里源,以提升更新速度。

一、在 "/etc/apt/sources.list" 文件头部添加:

#添加阿里源
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-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

二、执行如下命令更新源:

sudo apt-get update
sudo apt-get upgrade

三、其他几个国内备选源:

#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

#网易源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

如果出现下图这个错误,原因是第三方源(我添加的是阿里云的源)的公钥没有加入到 Ubuntu 服务器:

Err:1 http://mirrors.aliyun.com/ubuntu bionic InRelease                                   
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Hit:6 http://cn.archive.ubuntu.com/ubuntu jammy InRelease
Err:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Hit:7 http://cn.archive.ubuntu.com/ubuntu jammy-updates InRelease
Err:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Hit:8 http://cn.archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease

网上很多文章都给出了下面的指令进行修复(注意使用红色方框中的公钥):

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32

但在我的系统上会提示如下错误,应该是访问官方的 Keyserver 出现了问题:

andy@andy-ubuntu-server:~$ sudo gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: keyserver receive failed: Server indicated a failure

于是继续搜索,使用如下指令,更改了 Keyserver URL:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 3B4FE6ACC0B21F32

问题解决,如下提示,并成功更新国内源:

gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) " imported
gpg: Total number processed: 1
gpg:               imported: 1

sudo apt-get update
……
……
Get:12 http://mirrors.aliyun.com/ubuntu bionic/restricted amd64 Packages [9,184 B]   
Get:13 http://mirrors.aliyun.com/ubuntu bionic/restricted Translation-en [3,584 B]
Get:14 http://mirrors.aliyun.com/ubuntu bionic/universe amd64 Packages [8,570 kB]
Get:15 http://mirrors.aliyun.com/ubuntu bionic/universe Translation-en [4,941 kB]                                                                                                                                                                                                     
Get:16 http://mirrors.aliyun.com/ubuntu bionic/multiverse amd64 Packages [151 kB]                                                                                                                                                                                                     
Get:17 http://mirrors.aliyun.com/ubuntu bionic/multiverse Translation-en [108 kB]                                                                                                                                                                                                     
Get:18 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages [2,366 kB]                                                                                                                                                                                                
Get:19 http://mirrors.aliyun.com/ubuntu bionic-security/main Translation-en [410 kB]                                                                                                                                                                                                  
Get:20 http://mirrors.aliyun.com/ubuntu bionic-security/restricted amd64 Packages [859 kB]                                                                                                                                                                                            
Get:21 http://mirrors.aliyun.com/ubuntu bionic-security/restricted Translation-en [118 kB]                                                                                                                                                                                            
Get:22 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 Packages [1,223 kB]                                                                                                                                                                                            
Get:23 http://mirrors.aliyun.com/ubuntu bionic-security/universe Translation-en [282 kB]                                                                                                                                                                                              
Get:24 http://mirrors.aliyun.com/ubuntu bionic-security/multiverse amd64 Packages [19.0 kB]                                                                                                                                                                                           
Get:25 http://mirrors.aliyun.com/ubuntu bionic-security/multiverse Translation-en [3,836 B]                                                                                                                                                                                           
Get:26 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages [2,707 kB]                                                                                                                                                                                                 
Get:27 http://mirrors.aliyun.com/ubuntu bionic-updates/main Translation-en [500 kB]                                                                                                                                                                                                   
Get:28 http://mirrors.aliyun.com/ubuntu bionic-updates/restricted amd64 Packages [889 kB]                                                                                                                                                                                             
Get:29 http://mirrors.aliyun.com/ubuntu bionic-updates/restricted Translation-en [123 kB]                                                                                                                                                                                             
Get:30 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 Packages [1,837 kB]                                                                                                                                                                                             
Get:31 http://mirrors.aliyun.com/ubuntu bionic-updates/universe Translation-en [398 kB]                                                                                                                                                                                               
Get:32 http://mirrors.aliyun.com/ubuntu bionic-updates/multiverse amd64 Packages [24.9 kB]                                                                                                                                                                                            
Get:33 http://mirrors.aliyun.com/ubuntu bionic-updates/multiverse Translation-en [6,012 B]                                                                                                                                                                                            
Get:34 http://mirrors.aliyun.com/ubuntu bionic-proposed/main amd64 Packages [134 kB]                                                                                                                                                                                                  
Get:35 http://mirrors.aliyun.com/ubuntu bionic-proposed/main Translation-en [29.7 kB]                                                                                                                                                                                                 
Get:36 http://mirrors.aliyun.com/ubuntu bionic-proposed/restricted amd64 Packages [71.0 kB]                                                                                                                                                                                           
Get:37 http://mirrors.aliyun.com/ubuntu bionic-proposed/restricted Translation-en [9,800 B]                                                                                                                                                                                           
Get:38 http://mirrors.aliyun.com/ubuntu bionic-proposed/universe amd64 Packages [17.3 kB]                                                                                                                                                                                             
Get:39 http://mirrors.aliyun.com/ubuntu bionic-proposed/universe Translation-en [10.2 kB]                                                                                                                                                                                             
Get:40 http://mirrors.aliyun.com/ubuntu bionic-backports/main amd64 Packages [10.8 kB]                                                                                                                                                                                                
Get:41 http://mirrors.aliyun.com/ubuntu bionic-backports/main Translation-en [5,016 B]                                                                                                                                                                                                
Get:42 http://mirrors.aliyun.com/ubuntu bionic-backports/universe amd64 Packages [11.6 kB]                                                                                                                                                                                            
Get:43 http://mirrors.aliyun.com/ubuntu bionic-backports/universe Translation-en [5,864 B] 

另外,对于新安装的系统,也可能会遇到如下的错误:

E: Failed to fetch cdrom://Ubuntu-Server 16.04.3 LTS Xenial Xerus - Release amd64 (20170801)/dists/xenial/main/binary-amd64/Packages Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs E: Some index files failed to download. They have been ignored, or old ones used instead.

在 "/etc/apt/sources.list" 文件中注释掉这一行:

deb cdrom:[Ubuntu-Server 16.04.3 LTS _Xenial Xerus_ - Release amd64 (20170801)]/ xenial main restricted

Ubuntu

你可能感兴趣的:(将 Ubuntu 默认源修改为国内源)