当前位置 博文首页 > 谭青海:ubuntu 20.04 LTS 更换阿里云源

    谭青海:ubuntu 20.04 LTS 更换阿里云源

    作者:[db:作者] 时间:2021-09-21 15:05

    1. 备份下原始文件

    我们要修改的文件是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
    

    2. 查看系统版本信息

    其实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安装源时用的系统不一样。

    3. 修改文件

    vim source.list
    
    • 注释掉原来的,然后将下面的复制到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
    

    之类的也是可以的,之前我有这个疑惑,所以在这里一并告知和我有一样疑惑的朋友。

    4. 更新软件列表

    sudo  apt update
    

    5. 更新软件包

    sudo  apt upgrade
    

    6.最后几个问题?

    关于sudo apt-get update与sudo apt-get upgrade有什么区别,推荐一篇博文,一看就懂
    https://blog.csdn.net/Dreamhai/article/details/110195331

    cs
    下一篇:没有了