前言
每次装新系统都要网上搜各种换仓库镜像源的教程,有的还不一定准确,自己总结下,免得到处翻找
我一般最常用的是debian系统,centos因为变得不再稳定,所以我已不再使用,如果你用的是debian系,应该也适合你,如ubuntu。
以下教程都是在root用户使用,新用户还需要编辑sudoer文件,太麻烦了,索性直接用root用户,不过便于以后使用,以后可能普通用户也有换源的需求,有的命令也加上sudo
查看自己的debian发行版本
cat /etc/issue
# 或者
cat /proc/version
本次教程发行版本是 Debian 12 (bookworm)
debian的镜像源文件所在位置 /etc/apt/sources.list
修改之前先备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
清华源
官方帮助地址:https://mirrors.tuna.tsinghua.edu.cn/help/debian/
step 1
新系统更新软件缓存包时会用到 官方安全更新软件源
,国内网络问题,所以会直接卡住,所以先使用清华源更新,更新后再换回来
# 编辑 /etc/apt/sources.list
sudo vi /etc/apt/sources.list
快捷键:
- home键:光标跳转到行首
- dG:删除全部内容
在官网选择好对应的版本和内容如下:
- 是否使用 HTTPS:否
- 是否使用 sudo:是
- Debian 版本:Debian 12 (bookworm)
- 启用源码镜像:否
- 使用官方安全更新软件源:否
将复制的内容粘贴到终端
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
退出,更新缓存
sudo apt update
# 这一步安装好vim,便于后续使用
sudo apt install vim
step 2(可选)
Debian Buster 以上版本默认支持 HTTPS 源,所以可选。
安装:
- apt-transport-https
- ca-certificates
sudo apt install apt-transport-https ca-certificates
step 3
类似于step1,选择的内容则有所不同
- 是否使用 HTTPS:是
- 是否使用 sudo:是
- Debian 版本:Debian 12 (bookworm)
- 启用源码镜像:否
- 使用官方安全更新软件源:是
# 编辑 /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
更新缓存
sudo apt update
现在就可以自由安装软件了。
中科大
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list