当前位置 博文首页 > 谭青海:ubuntu 20.04 LTS 更换阿里云源
我们要修改的文件是
sources.list
,它在目录/etc/apt/
下,sources.list
是包管理工具apt
所用的记录软件包仓库位置的配置文件,同样类型的还有位于 同目录下sources.list.d
文件下的各种.list
后缀的各文件
# 进入/etc/apt 目录
cd /etc/apt
# 备份source.list文件
sudo cp source.list source.list.backup
其实Ubuntu20.04
版之前的任一版更改apt
源为国内源方法早就有了,内容大同小异,我们应当掌握其规律了,其实每一版内容不同的地方就是版本号(或者官方一点的说:系统代号
),所以我们先了解下新版本的系统代号:
使用如下命令:
lsb_release -c
得到本系统的系统代号,如下图所示:
我们可以看到新版本的Ubuntu系统代号为
focal
同样的我们也可以得到之前任意版本的系统代号:
Ubuntu 12.04(LTS)代号为precise
。
Ubuntu 14.04 (LTS)代号为trusty
。
Ubuntu 15.04 代号为vivid
。
Ubuntu 15.10 代号为wily
。
Ubuntu 16.04 (LTS)代号为xenial
。
Ubuntu 18.04 (LTS)代号为bionic
。
所以这也就解释了为什么我们百度出来的那么多方案里面内容不尽相同的原因,因为他们更改apt安装源时用的系统不一样。
vim source.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
值得注意的是sources.list文件的条目都是有格式的(通过上面的内容大家也看的出来),一般有如下形式
deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3
所以后面几个参数是对软件包的分类(Ubuntu下是main, restricted,universe ,multiverse这四个)
所以你把内容写成
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed universe multiverse
之类的也是可以的,之前我有这个疑惑,所以在这里一并告知和我有一样疑惑的朋友。
sudo apt update
sudo apt upgrade
关于sudo apt-get update与sudo apt-get upgrade有什么区别,推荐一篇博文,一看就懂
https://blog.csdn.net/Dreamhai/article/details/110195331