【Ubuntu】更换数据源

前言

我们常说的给 Ubuntu 换源,实际上是指的给 Debian/Ubuntu 系的 Linux 操作系统中的软件包管理器(Advanced Packaging Tool,APT)更换仓库地址

OSFormatToolsUpdate packages
Debian.debapt, apt-cache, apt-get, dpkgsudo apt-get update
Ubuntu.debapt, apt-cache, apt-get, dpkgsudo apt-get update
CentOS.rpmyumyum check-update
Fedora.rpmdnfdnf check-update
FreeBSD.txz, [Ports]pkg, [make]sudo pkg update [sudo portsnap fetch update]

回到正题,在国内使用官方源由于网络的问题下载太慢,因此我们一般需要更换到国内的一些镜像站提供的数据源

更换方案

Ubuntu 的源存放在 /etc/apt/sources.list 下,以 18.04 LTS 版本为例,内容如下

$ cat /etc/apt/sources.list
#deb cdrom:[Ubuntu 18.04.5 LTS _Bionic Beaver_ - Release amd64 (20200806.1)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-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://us.archive.ubuntu.com/ubuntu/ bionic universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic universe
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-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://us.archive.ubuntu.com/ubuntu/ bionic multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-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://us.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-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 bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://security.ubuntu.com/ubuntu bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse

方案一:手动更换源列表

大致步骤如下

  1. 备份官方源 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 按照镜像站提供信息覆盖文件 sudo vim /etc/apt/sources.list

收集到的一些国内镜像源地址

镜像源Help link
中科大 USTChttps://mirrors.ustc.edu.cn/help/ubuntu.html
阿里云 aliyunhttps://developer.aliyun.com/mirror/ubuntu
清华 tsinghuahttps://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
网易 163https://mirrors.163.com/.help/ubuntu.html

清华源比较直接,选好 Ubuntu 发行版本复制内容到 sources.list 即可

方案二:通过图形化界面更新

打开文件夹 /etc/apt,双击 sources.list,会自动展开相关设置
sources.list
选择 other
choose other
选择 China 中的某个镜像源,如阿里云,完成
aliyun

方案三:脚本自动化更新

待实现 TODO

参考

[1] Ubuntu 换源看这一篇就够了:https://cloud.tencent.com/developer/article/1880981
[2] Linux 包管理基础:apt、yum、dnf 和 pkg :https://linux.cn/article-8782-1.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值