Debian 更换软件源

Ubuntu 20.4 LTS 更换软件源

  • 更换阿里云软件源
1
2
3
4
5
6
7
8
# 备份配置文件
# cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 清空配置文件内容
# echo "" > /etc/apt/sources.list

# 编辑配置文件,添加以下内容
# vi /etc/apt/sources.list
1
2
3
4
5
6
7
8
9
10
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
  • 使阿里云软件源生效
1
2
# 更新软件索引
# apt-get update

Debian 9(Stretch)更换软件源

  • 更换阿里云软件源
1
2
3
4
5
6
7
8
# 备份配置文件
# cp /etc/apt/sources.list /etc/apt/backup.sources.list

# 清空配置文件内容
# echo "" > /etc/apt/sources.list

# 编辑配置文件,添加以下内容
# vi /etc/apt/sources.list
1
2
3
4
5
6
7
8
deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
  • 使阿里云软件源生效(必须)
1
2
# 更新软件索引
# apt-get update
  • 更新软件和系统(非必须,请谨慎操作)
1
2
3
4
5
# 升级系统里的所有软件
# apt-get upgrade

# 升级系统版本
# apt-get dist-upgrade
  • 若是构建 Docker 镜像,那么在 Dockerfile 里可以使用以下指令
1
2
3
4
5
6
7
8
9
10
11
12
13
RUN cp /etc/apt/sources.list /etc/apt/backup.sources.list
&& echo "deb http://mirrors.163.com/debian/ stretch main non-free contrib" > /etc/apt/sources.list \
&& echo "deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian/ stretch main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib" >> /etc/apt/sources.list

RUN apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y autoclean && apt-get -y autoremove

Debian 11(Bullseye)更换软件源

  • 更换 163 软件源
1
2
3
4
5
6
7
8
# 备份配置文件
# cp /etc/apt/sources.list /etc/apt/backup.sources.list

# 清空配置文件内容
# echo "" > /etc/apt/sources.list

# 编辑配置文件,添加以下内容
# vi /etc/apt/sources.list
1
2
3
4
5
6
7
8
deb http://mirrors.163.com/debian/ bullseye main non-free contrib
deb http://mirrors.163.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.163.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib
deb http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib
deb-src http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib
  • 使 163 软件源生效(必须)
1
2
# 更新软件索引
# apt-get update
  • 更新软件和系统(非必须,请谨慎操作)
1
2
3
4
5
# 升级系统里的所有软件
# apt-get upgrade

# 升级系统版本
# apt-get dist-upgrade
  • 若是构建 Docker 镜像,那么在 Dockerfile 里可以使用以下指令
1
2
3
4
5
6
7
8
9
10
11
12
13
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& echo "deb http://mirrors.163.com/debian/ bullseye main non-free contrib" > /etc/apt/sources.list \
&& echo "deb http://mirrors.163.com/debian/ bullseye-updates main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.163.com/debian/ bullseye-backports main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian/ bullseye main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb-src http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib" >> /etc/apt/sources.list

RUN apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y autoclean && apt-get -y autoremove

Debian 12(Bookworm)更换软件源

  • 更换清华软件源
1
2
3
4
5
6
7
8
# 备份配置文件
# cp /etc/apt/sources.list /etc/apt/backup.sources.list

# 清空配置文件内容
# echo "" > /etc/apt/sources.list

# 编辑配置文件,添加以下内容
# vi /etc/apt/sources.list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
2
# 更新软件索引
# apt-get update
  • 更新软件和系统(非必须,请谨慎操作)
1
2
3
4
5
# 升级系统里的所有软件
# apt-get upgrade

# 升级系统版本
# apt-get dist-upgrade