前言
每次装新系统都要网上搜各种换仓库镜像源的教程,有的还不一定准确,自己总结下,免得到处翻找
我一般用的是 Debian 系统,Centos 因为变得不再稳定,所以我已不再使用,如果你用的是 Debian 系,应该也适合你,如 Ubuntu。
以下教程都是在 root 用户使用,新用户还需要编辑 sudoer 文件,太麻烦了,索性直接用 roo t用户,不过便于以后使用,以后可能普通用户也有换源的需求,有的命令也加上 sudo
查看自己的 Debian 发行版本
1
2
3
4
|
cat /etc/issue
# 或者
cat /proc/version
|
本次教程发行版本是 Debian 12 (bookworm)
Debian 软件源文件所在位置 /etc/apt/sources.list
修改之前先备份
1
|
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
|
清华源
官方帮助地址:https://mirrors.tuna.tsinghua.edu.cn/help/debian/
Step 1
新系统更新软件缓存包时会用到 官方安全更新软件源
,国内网络问题,所以会直接卡住,所以先使用清华源更新,更新后再换回来
1
2
|
# 编辑 /etc/apt/sources.list
sudo vi /etc/apt/sources.list
|
快捷键:
在官网选择好对应的版本和内容如下:
- 是否使用 HTTPS:否
- 是否使用 sudo:是
- Debian 版本:Debian 12 (bookworm)
- 启用源码镜像:否
- 使用官方安全更新软件源:否
将复制的内容粘贴到终端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# # deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
|
退出,更新缓存
1
2
3
4
|
sudo apt update
# 这一步安装好vim,便于后续使用
sudo apt install vim
|
Step 2(可选)
Debian Buster 以上版本默认支持 HTTPS 源,所以可选。
安装:
- apt-transport-https
- ca-certificates
1
|
sudo apt install apt-transport-https ca-certificates
|
Step 3
类似于step1,选择的内容则有所不同
- 是否使用 HTTPS:==是==
- 是否使用 sudo:是
- Debian 版本:Debian 12 (bookworm)
- 启用源码镜像:否
- 使用官方安全更新软件源:==是==
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# 编辑 /etc/apt/sources.list
sudo vim /etc/apt/sources.list
# 删除全部内容,粘贴重新复制的内容
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
|
更新缓存
现在就可以自由安装软件了。
中科大
1
|
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
|
阿里云
参考地址:https://developer.aliyun.com/mirror/debian?spm=a2c6h.13651102.0.0.7fb11b11uZIZXw
Debian10
此源为阿里云的云服务器默认配置,使用阿里云镜像站的源下载速度很慢,不知为何。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
## or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.debian.tmpl
###
# See http://www.debian.org/releases/stable/i386/release-notes/ch-upgrading.html
# for how to upgrade to newer versions of the distribution.
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye main contrib non-free
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-updates main contrib non-free
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-proposed-updates main non-free contrib
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-backports main non-free contrib
## Major bug fix updates produced after the final release of the
## distribution.
deb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-updates main contrib non-free
deb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye main contrib non-free
deb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-proposed-updates main contrib non-free
deb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-backports main contrib non-free
deb http://mirrors.cloud.aliyuncs.com/debian-security/ bullseye-security main non-free contrib
deb-src http://mirrors.cloud.aliyuncs.com/debian-security/ bullseye-security main non-free contrib
## Uncomment the following two lines to add software from the 'backports'
## repository.
##
## 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.
|