Royc30ne

Royc30ne

机器学习 | 联邦学习 | VPS | 摄影 | 日常

[Linux指南] 记录一下Ubuntu更换软件源的具体步骤

查找可用的 Ubuntu 软件源#

首先,需要查找可用的 Ubuntu 软件源。我们可以在网络上找到一些可用的 Ubuntu 软件源,也可以在国内的一些开源镜像站点上查找。建议选择离自己地理位置较近的 Ubuntu 软件源,以获得更快的下载速度。

备份 Ubuntu 默认软件源#

在更换 Ubuntu 软件源之前,建议备份原有的软件源列表,以便在需要时可以恢复。备份方法是将默认软件源列表文件复制到其他位置并重命名,例如:

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

更换 Ubuntu 软件源#

更换 Ubuntu 软件源需要编辑 /etc/apt/sources.list 文件。使用文本编辑器打开文件并注释掉原有的软件源(在行首加上 # 符号),然后添加新的软件源地址。例如,我们可以使用清华大学的开源镜像站点作为新的 Ubuntu 软件源地址:

#deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted
#deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
#deb http://archive.ubuntu.com/ubuntu/ focal universe
#deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
#deb http://archive.ubuntu.com/ubuntu/ focal multiverse
#deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
#deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
#deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
#deb http://security.ubuntu.com/ubuntu/ focal-security universe
#deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

注意,新的软件源地址需要使用 debdeb-src 开头,分别表示二进制文件和源代码文件的地址。

更新软件源缓存#

更换完 Ubuntu 软件源之后,需要更新软件源缓存。可以使用以下命令更新缓存:

sudo apt update & apt upgrade

如何验证更换 Ubuntu 软件源的效果?#

更换 Ubuntu 软件源之后,可以使用以下命令验证新的软件源是否生效:

apt-cache policy package-name

其中,package-name 是软件包的名称,可以输入任意已安装的软件包名称来验证。如果软件包可以从新的软件源下载,则说明更换 Ubuntu 软件源成功。

Appendix: 国内常用源#

#网易163源

deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse

#阿里云源

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

#清华源

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

#中科大源

deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

FAQ#

1. 更换 Ubuntu 软件源会影响系统安全性吗?#

不会。更换 Ubuntu 软件源并不会影响系统的安全性,只是会改变软件包的来源。建议使用经过认证和验证的官方软件源或者可信的开源镜像站点。

2. 如何查找可用的 Ubuntu 软件源地址?#

可以在网络上搜索可用的 Ubuntu 软件源地址,也可以在国内的一些开源镜像站点上查找。建议选择离自己地理位置较近的 Ubuntu 软件源,以获得更快的下载速度。

3. 更换 Ubuntu 软件源会导致软件包版本冲突吗?#

可能会。更换 Ubuntu 软件源可能会导致软件包版本冲突或者依赖关系不满足等问题。建议在更换 Ubuntu 软件源前备份原有的软件源列表,并根据实际情况选择合适的软件源地址。

4. 如何恢复到默认的 Ubuntu 软件源?#

可以按照本文中提到的步骤进行恢复,需要注意备份当前的软件源列表、更新软件源缓存等步骤。

5. 更换 Ubuntu 软件源是否会影响已安装的软件包?#

不会。更换 Ubuntu 软件源并不会影响已安装的软件包,只是会改变以后安装、更新、卸载软件包时的来源。已安装的软件包

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。