知识分享之Ubuntu——修改Ubuntu源
背景
日常我们开发时,我们会遇到各种各样的奇奇怪怪的问题(踩坑o(╯□╰)o),这个常见问题系列就是我日常遇到的一些问题的记录文章系列,这里整理汇总后分享给大家,让其还在深坑中的小伙伴有绳索能爬出来。
同时在这里也欢迎大家把自己遇到的问题留言或私信给我,我看看其能否给大家解决。
全文使用环境:
- 操作系统:Ubuntu 20.04.3
- 硬件:Vmware虚拟机 4核 8G内存 200G存储
正文
在我们进行使用Ubuntu系统时经常需要安装各种各样的软件,而系统默认安装完成后,其所使用的源是官方地址下的默认源,这个源在国内有时并不是很稳定,因此我们就需要进行修改为国内的一些常见源。
国内比较常见的源例如:
阿里云源:http://mirrors.aliyun.com/ubuntu/dists/
网易源:http://mirrors.163.com/ubuntu/
清华源:https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
中科大源:https://mirrors.ustc.edu.cn/ubuntu/
下面我以阿里云源为例开始进行更换本系统的源
1、备份原有源,便于以后使用时快速恢复。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.2021.10.09.bak
2、查看当前Ubuntu的Codename是什么标记
lsb_release -a
cnhuashao@cnhuashao:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
这里注意Codename,记住它,打开阿里云源地址,找到和Codename一样文件索引地址,不需要点击进入~~~
image-20211009095139719备注:这里Codename也可以直接查看/etc/apt/sources.list中默认源使用的标记是什么,通常类似下方图中的样子
image-202110090954298203、修改/etc/apt/sources.list中的内容,替换里面的url地址,并去除里面的注释,便于查看修改。
关键命令sudo vim /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
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu focal universe
# deb-src http://cn.archive.ubuntu.com/ubuntu focal universe
deb http://cn.archive.ubuntu.com/ubuntu focal-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu focal multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal multiverse
deb http://cn.archive.ubuntu.com/ubuntu focal-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
deb http://cn.archive.ubuntu.com/ubuntu focal-security main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-security main restricted
deb http://cn.archive.ubuntu.com/ubuntu focal-security universe
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-security universe
deb http://cn.archive.ubuntu.com/ubuntu focal-security multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-security multiverse
替换后的内容
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
4、执行更新缓存和升级操作,并观察过程中使用的安装包位置来源。
image-20211009100642493至此替换源完成。
本文声明:
知识共享许可协议
本作品由 cn華少 采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
网友评论