Debian12的apt换源,更换快速的国内镜像源 笔记250314

要将Debian 12的APT源更换为快速的国内镜像源,您可以按照以下步骤操作:

一、备份原始sources.list文件

在修改任何重要的系统文件之前,建议先创建备份副本,以防万一出现问题能够快速恢复原状。使用以下命令备份/etc/apt/sources.list文件:

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

或带日期时间

tempSmbDotConfUri=/etc/apt/sources.list ;    sudo cp -a ${tempSmbDotConfUri} ${tempSmbDotConfUri}.$(date +%0y%0m%0d_%0H%0M%0S_ns%0N).bak

二、选择国内镜像源

Debian 12(代号Bookworm)有多个国内镜像源可供选择,以下是一些常用的选项:

  1. 阿里云镜像站

    deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
    deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
    deb http://mirrors.aliyun.com/debian-security bookworm-security main
    deb http://mirrors.aliyun.com/debian bookworm-updates main non-free contrib
    deb-src http://mirrors.aliyun.com/debian bookworm-updates main non-free contrib
    deb http://mirrors.aliyun.com/debian bookworm-backports main non-free contrib
    deb-src http://mirrors.aliyun.com/debian bookworm-backports main non-free contrib
    
  2. 腾讯云镜像站

    deb https://mirrors.cloud.tencent.com/debian bookworm main non-free contrib
    deb-src https://mirrors.cloud.tencent.com/debian bookworm main non-free contrib
    deb https://mirrors.cloud.tencent.com/debian-security bookworm-security main
    deb https://mirrors.cloud.tencent.com/debian bookworm-updates main non-free contrib
    deb-src https://mirrors.cloud.tencent.com/debian bookworm-updates main non-free contrib
    deb https://mirrors.cloud.tencent.com/debian bookworm-backports main non-free contrib
    deb-src https://mirrors.cloud.tencent.com/debian bookworm-backports main non-free contrib
    
  3. 清华大学开源软件镜像站

    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main
    
  4. 中国科学技术大学镜像站

    deb https://mirrors.ustc.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
    deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
    
  5. 网易镜像站

    deb https://mirrors.163.com/debian/ bookworm main non-free contrib non-free-firmware
    deb-src https://mirrors.163.com/debian/ bookworm main non-free contrib non-free-firmware
    deb https://mirrors.163.com/debian-security/ bookworm-security main
    deb-src https://mirrors.163.com/debian-security/ bookworm-security main
    deb https://mirrors.163.com/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb-src https://mirrors.163.com/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb https://mirrors.163.com/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb-src https://mirrors.163.com/debian/ bookworm-backports main non-free contrib non-free-firmware
    

deb-src 的行可以资源注释掉, 不下载源码, 如 清华源的示例: https://mirrors.tuna.tsinghua.edu.cn/help/debian/

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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://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

中文注释最好去掉, 显示不正常

可以用 http 也可用 https ,

  • http好处是快,
  • https好处是不会被运行商缓存劫持

编辑sources.list文件

使用文本编辑器(如nanovim)打开/etc/apt/sources.list文件,将里面的内容替换为上面选择的国内镜像源。例如,使用nano编辑器:

sudo nano /etc/apt/sources.list
sudo vi /etc/apt/sources.list

将编辑器中的内容全部删除,然后粘贴您选择的国内镜像源。粘贴完成后,按Ctrl+X,然后按Y确认保存,最后按Enter键退出编辑器。

用脚本设置快速

    用脚本设置阿里源:
#!/bin/bash

# 备份原有的源列表文件
tempSmbDotConfUri=/etc/apt/sources.list
sudo cp -a ${tempSmbDotConfUri} ${tempSmbDotConfUri}.$(date +%0y%0m%0d_%0H%0M%0S_ns%0N).bak

# 选择阿里云镜像源
cat <<EOF | sudo tee /etc/apt/sources.list
deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
EOF

# 更新软件包索引
sudo apt update

阿里源,不下载源码

#!/bin/bash

# 备份原有的源列表文件
tempSmbDotConfUri=/etc/apt/sources.list
sudo cp -a ${tempSmbDotConfUri} ${tempSmbDotConfUri}.$(date +%0y%0m%0d_%0H%0M%0S_ns%0N).bak

# 选择阿里云镜像源
cat <<EOF | sudo tee /etc/apt/sources.list
deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
# deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
# deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
# deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
# deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
EOF

# 更新软件包索引
sudo apt update
    用脚本设置中科大源:
#!/bin/bash

# 备份原有的源列表文件
tempSmbDotConfUri=/etc/apt/sources.list
sudo cp -a ${tempSmbDotConfUri} ${tempSmbDotConfUri}.$(date +%0y%0m%0d_%0H%0M%0S_ns%0N).bak

# 选择阿里云镜像源
cat <<EOF | sudo tee /etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
EOF

# 更新软件包索引
sudo apt update



更新本地包索引数据库

为了让这些改动生效,需要执行以下命令刷新系统的软件仓库缓存信息:

sudo apt update

执行完该命令后,APT工具将重新同步最新的元数据,确保后续安装操作能顺利进行。

升级软件包(可选)

如果您希望同时升级已安装的软件包,可以执行以下命令:

sudo apt upgrade

这将根据新的软件仓库信息,升级所有可升级的软件包。









以下是Debian 12(代号 bookworm)更换国内APT镜像源的详细步骤和推荐源配置,综合了多个来源的验证信息:


步骤一:备份原配置文件

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

备份原始源文件以防止配置错误。


步骤二:编辑源配置文件
使用文本编辑器(如 nano)打开 /etc/apt/sources.list 文件:

sudo nano /etc/apt/sources.list

清空或注释原有内容,替换为以下国内镜像源配置(任选其一):

1. 清华大学镜像站(推荐)

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-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

2. 阿里云镜像站

deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib

3. 中国科学技术大学(USTC)镜像站

deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware

4. 华为云镜像站

deb https://mirrors.huaweicloud.com/debian/ bookworm main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian/ bookworm main contrib non-free
deb https://mirrors.huaweicloud.com/debian-security/ bookworm-security main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian-security/ bookworm-security main contrib non-free

步骤三:更新软件包列表

sudo apt update
sudo apt upgrade -y

执行更新以确保新源生效。


注意事项

  1. 容器环境:若在Docker等容器中使用Debian 12,默认源配置文件可能位于 /etc/apt/sources.list.d/debian.sources,需使用 sed 命令替换(例如华为云):

    sed -i 's@deb.debian.org@repo.huaweicloud.com@g' /etc/apt/sources.list.d/debian.sources
    
  2. 组件说明

    • main:官方开源软件。
    • contrib:依赖非自由软件的第三方开源软件。
    • non-free:非自由软件。
    • non-free-firmware:非自由固件(Debian 12新增组件)。
  3. 其他推荐源:腾讯云、网易163、上海交大等镜像站也适用,具体配置可参考镜像站官方文档


常见问题

  • 更新失败:检查镜像站URL是否包含 bookworm 版本标识,或尝试更换其他镜像源。
  • 安全更新缺失:确保包含 bookworm-security 条目。

通过上述步骤,可显著提升软件下载速度。若需更多镜像源或详细配置,可访问清华大学镜像站阿里云镜像站









要将Debian 12的APT源更换为快速的国内镜像源,您可以按照以下步骤操作:

一、备份原始sources.list文件

在修改任何重要的系统文件之前,建议先创建备份副本,以防万一出现问题能够快速恢复原状。使用以下命令备份/etc/apt/sources.list文件:

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

二、选择国内镜像源

Debian 12(代号Bookworm)有多个国内镜像源可供选择,以下是一些常用的选项:

  1. 阿里云镜像站

    deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
    deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
    deb http://mirrors.aliyun.com/debian-security bookworm-security main
    deb http://mirrors.aliyun.com/debian bookworm-updates main non-free contrib
    deb-src http://mirrors.aliyun.com/debian bookworm-updates main non-free contrib
    deb http://mirrors.aliyun.com/debian bookworm-backports main non-free contrib
    deb-src http://mirrors.aliyun.com/debian bookworm-backports main non-free contrib
    
  2. 腾讯云镜像站

    deb https://mirrors.cloud.tencent.com/debian bookworm main non-free contrib
    deb-src https://mirrors.cloud.tencent.com/debian bookworm main non-free contrib
    deb https://mirrors.cloud.tencent.com/debian-security bookworm-security main
    deb https://mirrors.cloud.tencent.com/debian bookworm-updates main non-free contrib
    deb-src https://mirrors.cloud.tencent.com/debian bookworm-updates main non-free contrib
    deb https://mirrors.cloud.tencent.com/debian bookworm-backports main non-free contrib
    deb-src https://mirrors.cloud.tencent.com/debian bookworm-backports main non-free contrib
    
  3. 清华大学开源软件镜像站

    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main
    
  4. 中国科学技术大学镜像站

    deb https://mirrors.ustc.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main non-free contrib non-free-firmware
    deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
    deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
    
  5. 网易镜像站

    deb https://mirrors.163.com/debian/ bookworm main non-free contrib non-free-firmware
    deb-src https://mirrors.163.com/debian/ bookworm main non-free contrib non-free-firmware
    deb https://mirrors.163.com/debian-security/ bookworm-security main
    deb-src https://mirrors.163.com/debian-security/ bookworm-security main
    deb https://mirrors.163.com/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb-src https://mirrors.163.com/debian/ bookworm-updates main non-free contrib non-free-firmware
    deb https://mirrors.163.com/debian/ bookworm-backports main non-free contrib non-free-firmware
    deb-src https://mirrors.163.com/debian/ bookworm-backports main non-free contrib non-free-firmware
    

三、编辑sources.list文件

使用文本编辑器(如nanovim)打开/etc/apt/sources.list文件,将里面的内容替换为上面选择的国内镜像源。例如,使用nano编辑器:

sudo nano /etc/apt/sources.list

将编辑器中的内容全部删除,然后粘贴您选择的国内镜像源。粘贴完成后,按Ctrl+X,然后按Y确认保存,最后按Enter键退出编辑器。

四、更新本地包索引数据库

为了让这些改动生效,需要执行以下命令刷新系统的软件仓库缓存信息:

sudo apt update

执行完该命令后,APT工具将重新同步最新的元数据,确保后续安装操作能顺利进行。

五、升级软件包(可选)

如果您希望同时升级已安装的软件包,可以执行以下命令:

sudo apt upgrade

这将根据新的软件仓库信息,升级所有可升级的软件包。

通过以上步骤,您就可以成功将Debian 12的APT源更换为快速的国内镜像源,从而提升软件包的下载速度和稳定性。









针对Debian12的apt换源问题,更换为快速的国内镜像源是一个优化下载速度和稳定性的有效方法。以下是一些详细的步骤和推荐的国内镜像源:

一、备份原始sources.list文件

在修改任何重要的系统文件之前,建议先创建备份副本,以防出现问题时能够快速恢复原状。可以使用以下命令:

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

二、编辑sources.list文件

接下来,需要打开/etc/apt/sources.list文件并编辑其中的内容,以指定想要使用的国内镜像源。可以使用文本编辑器(如nano或vim)打开该文件。

三、选择并添加国内镜像源

以下是几个常用的中国境内Debian12(Bookworm)版本的镜像源,可以根据实际情况选择其中一个或多个:

  1. 阿里云镜像站
deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free
deb-src http://mirrors.aliyun.com/debian/ bookworm main contrib non-free
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free
  1. 腾讯云镜像站
deb https://mirrors.cloud.tencent.com/debian/ bookworm main contrib non-free
deb-src https://mirrors.cloud.tencent.com/debian/ bookworm main contrib non-free
deb https://mirrors.cloud.tencent.com/debian-security/ bookworm-security main
deb https://mirrors.cloud.tencent.com/debian/ bookworm-updates main contrib non-free
  1. 清华大学镜像站

    • 访问清华大学开源软件镜像站,根据页面提供的指引和Debian的版本信息,找到对应的镜像源地址,并替换到/etc/apt/sources.list文件中。
  2. 南京大学镜像站

deb http://mirror.nju.edu.cn/debian/ bookworm main contrib non-free
deb-src http://mirror.nju.edu.cn/debian/ bookworm main contrib non-free

(注意:南京大学镜像站可能不包含所有的安全更新和更新包,因此建议结合其他镜像站使用或定期访问以获取最新的信息。)

  1. 网易镜像站
deb https://mirrors.163.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.163.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.163.com/debian-security/ bookworm-security main
deb-src https://mirrors.163.com/debian-security/ bookworm-security main
deb https://mirrors.163.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.163.com/debian/ bookworm-updates main non-free non-free-firmware contrib

四、保存并退出编辑器

完成编辑后,保存所做的更改并退出编辑器。

五、更新本地包索引数据库

为了让这些改动生效,需要执行以下命令来刷新系统的软件仓库缓存信息:

sudo apt update && sudo apt upgrade

或者分开执行:

sudo apt update
sudo apt upgrade

通过以上步骤,就可以成功将Debian12的apt源更换为更快捷稳定的国内镜像源了。这将有助于提升软件包的下载速度和系统的稳定性。









在Debian 12 “Bookworm” 中更换APT源以使用国内镜像可以显著加快软件包的下载速度。以下是详细的步骤来更换为阿里云、清华大学或中科大的镜像源:

备份现有的源列表

在进行任何更改之前,首先备份现有的/etc/apt/sources.list.d/debian.sources文件(注意:对于容器镜像,配置文件位置有所不同)或者/etc/apt/sources.list文件。这一步非常重要,以防需要回滚到原始设置。

sudo cp /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list.d/debian.sources.bak
# 或者如果是在传统系统中
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

编辑源列表

接下来,你可以使用你喜欢的文本编辑器来编辑源列表文件。这里我们使用nano作为例子:

对于容器镜像

sudo nano /etc/apt/sources.list.d/debian.sources

你需要替换其中的URL为国内镜像站的地址。例如,若要使用阿里云的镜像,可以使用sed命令快速替换:

sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources

对于传统系统

如果你是在传统的Debian安装环境中工作,则需要编辑/etc/apt/sources.list文件:

sudo nano /etc/apt/sources.list

然后将默认的源地址替换为国内镜像地址。例如,下面是阿里云的源配置示例:

deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib

同样的方法适用于其他镜像站点,如清华大学、中科大等。

更新软件包列表

完成上述更改后,记得更新APT包索引:

sudo apt update

这将使你的系统识别新的软件源,并准备从这些源下载软件包。

升级已安装的软件包

如果需要升级所有已安装的软件包到最新版本,可以运行:

sudo apt upgrade

通过以上步骤,你就可以成功地将Debian 12的APT源更换为更快的国内镜像源了。请确保选择一个可靠的镜像站点,以保证软件包的完整性和安全性。此外,定期检查是否有官方源更新或更优的镜像源是保持系统健康的重要步骤。









在Debian 12中更换为国内快速镜像源能加快软件包的下载速度。以下是具体的操作步骤:

1. 备份原有的源列表文件
在修改源列表文件之前,建议先备份,以防后续出现问题可以恢复。执行下面的命令:

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

2. 选择合适的国内镜像源
下面为你提供几个常用的国内镜像源,你可以按需选择:

阿里云镜像源

deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib

清华大学镜像源

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free

3. 修改源列表文件
你可以使用文本编辑器(如 nanovim)来修改 /etc/apt/sources.list 文件。以 nano 为例,执行以下命令:

sudo nano /etc/apt/sources.list

把文件里的原有内容替换成你所选的镜像源内容,然后按 Ctrl + X,接着按 Y 确认保存,最后按 Enter 退出。

4. 更新软件包索引
修改完源列表文件后,需要更新软件包索引,让新的镜像源生效。执行下面的命令:

sudo apt update

以下是完整的操作脚本示例,你可以复制到本地执行:

#!/bin/bash

# 备份原有的源列表文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 选择阿里云镜像源
cat <<EOF | sudo tee /etc/apt/sources.list
deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
EOF

# 更新软件包索引
sudo apt update

你可以把上述脚本保存为一个 .sh 文件(例如 change_apt_source.sh),然后赋予执行权限并运行:

chmod +x change_apt_source.sh
./change_apt_source.sh









在使用 Debian 12 时,如果默认的 apt 源下载速度较慢,可以将其更换为国内的镜像源,以提高软件包的下载和更新速度。以下是更换 apt 源的详细步骤:

1. 备份原有 apt 源
在修改 apt 源之前,建议先备份原有的 sources.list 文件,以防需要恢复。

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

2. 选择合适的国内源
国内有多个高速镜像源可供选择,常见的有:

  • 清华大学:https://mirrors.tuna.tsinghua.edu.cn
  • 阿里云:https://mirrors.aliyun.com
  • 中国科技大学:https://mirrors.ustc.edu.cn
  • 腾讯云:https://mirrors.tencent.com

3. 修改 apt 源
编辑 /etc/apt/sources.list 文件,将文件内容替换为合适的国内镜像。例如,使用清华大学的镜像源:

sudo nano /etc/apt/sources.list

将文件内容替换为:

# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bookworm-security main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free

或者,如果需要使用 DEB822 格式(Debian 12 推荐),可以创建一个新的文件 /etc/apt/sources.list.d/debian.sources

sudo nano /etc/apt/sources.list.d/debian.sources

添加以下内容:

Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

4. 更新 apt 缓存
修改完成后,运行以下命令使更改生效:

sudo apt update

5. 可选:升级系统软件包
如果希望检查更新并升级系统软件包,可以执行:

sudo apt upgrade -y

通过以上步骤,就可以将 Debian 12 的 apt 源更换为国内的镜像源,从而提高软件包的下载和更新速度。









在Debian 12中更换APT源为国内镜像源可以显著提高软件包下载速度。以下是详细步骤:

方法一:手动编辑sources.list文件

  1. 备份当前的sources.list文件

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 编辑sources.list文件

    sudo nano /etc/apt/sources.list
    
  3. 替换为国内镜像源
    你可以选择以下任意一个国内镜像源:

    • 阿里云镜像源

      deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
      deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
      
      deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
      deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
      
      deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
      deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
      
      deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
      deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
      
    • 清华大学镜像源

      deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main non-free contrib
      deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main non-free contrib
      
      deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main
      deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main
      
      deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main non-free contrib
      deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main non-free contrib
      
      deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main non-free contrib
      deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main non-free contrib
      

    将上述内容复制并粘贴到sources.list文件中,替换原有内容。

  4. 保存并退出编辑器
    Ctrl+X,然后按Y确认保存,最后按Enter退出。

  5. 更新APT包列表

    sudo apt update
    

方法二:使用镜像源配置工具

Debian 12提供了apt-spy工具,可以自动选择最快的镜像源。

  1. 安装apt-spy

    sudo apt install apt-spy
    
  2. 更新APT包列表

    sudo apt update
    
  3. 使用apt-spy选择最快的镜像源

    sudo apt-spy update
    sudo apt-spy fix --mirror=http://mirrors.aliyun.com/debian/ --host=mirrors.aliyun.com
    
  4. 更新APT包列表

    sudo apt update
    

通过以上步骤,你可以成功更换Debian 12的APT源为国内镜像源,从而提高软件包下载速度。









Debian 12 更换 APT 国内镜像源步骤


一、为什么要换源?
Debian 官方服务器位于国外,国内用户直接访问速度较慢。更换为国内镜像源可显著提升软件下载速度,例如:

  • 清华源(Tuna)
  • 阿里云
  • 中科大源(USTC)
  • 华为云

二、操作步骤

  1. 备份原始源文件
    为防止意外,先备份系统默认源:

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 编辑源文件
    使用 nano 或其他文本编辑器修改配置文件:

    sudo nano /etc/apt/sources.list
    
  3. 替换为国内镜像源
    删除原有内容,根据需求选择以下镜像源之一粘贴(以 bookworm 为例):

    • 清华源(推荐):

      deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
      deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
      deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
      deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free
      
    • 阿里云

      deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free
      deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free
      deb https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free
      deb https://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free
      
    • 中科大源

      deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free
      deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free
      deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free
      deb https://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free
      
  4. 保存并退出编辑器

    • nano:按 Ctrl+O 保存 → 按 Ctrl+X 退出。
  5. 更新软件列表
    使新配置生效:

    sudo apt update
    

三、验证是否成功
执行 apt update 后,观察输出是否正常:

  • ✅ 成功:显示新镜像源地址(如 mirrors.tuna.tsinghua.edu.cn)且无错误。
  • ❌ 失败:检查网络连接或源文件语法。

四、常见问题

  1. 如何恢复默认源?

    sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
    sudo apt update
    
  2. 是否需要启用 non-free 组件?
    若需使用闭源驱动(如显卡驱动),建议保留 contrib non-free 字段。

  3. HTTPS 和 HTTP 如何选择?
    HTTPS 更安全,但 HTTP 速度略快。国内镜像源两者均可靠。


五、扩展建议

  • 多源混合使用:可通过 sources.list.d/ 目录分文件管理不同源。
  • 区域优选:根据地理位置选择镜像(如南方用户选阿里云,北方选清华源)。









以下是 Debian 12(bookworm)更换国内镜像源的详细步骤及注意事项,结合最新技术网页整理:


一、备份原配置文件
操作前务必备份原配置文件,避免误操作导致系统异常:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp -r /etc/apt/sources.list.d /etc/apt/sources.list.d.bak

引用:


二、编辑镜像源配置
方式1:直接修改 /etc/apt/sources.list(传统格式)

sudo nano /etc/apt/sources.list

推荐配置(中科大源)

deb http://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

注:需添加 non-free-firmware 组件以支持新硬件

其他国内源示例
阿里云源

deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware

清华大学源

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm 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

引用:

方式2:使用 DEB822 格式(Debian 12 新特性)

sudo nano /etc/apt/sources.list.d/debian.sources
Types: deb
URIs: https://mirrors.ustc.edu.cn/debian
Suites: bookworm bookworm-updates
Components: main contrib non-free non-free-firmware

引用:


三、更新软件包索引

sudo apt update

若提示证书验证失败(如清华源 HTTPS 问题),可临时关闭验证:

sudo apt update --allow-insecure-repositories

引用:


四、高级配置建议

  1. 启用 HTTPS 加速
    修改为 https 协议(如清华源),避免运营商缓存劫持。

  2. 关闭 HTTP Pipelining
    /etc/apt/apt.conf.d/99nopipelining 中添加:

    Acquire::http::Pipeline-Depth "0";
    

    解决高带宽下载时的连接重置问题

  3. 一键换源脚本
    使用脚本快速切换(需执行 chmod +x manage_sources.sh):

    # 添加阿里云源
    sudo ./manage_sources.sh aliyun
    # 添加清华源
    sudo ./manage_sources.sh qinghua
    

    引用:


五、常见问题处理

  1. 命令报错 command not found
    • 原因:未加载完整环境变量(如 PATH 缺失 /sbin)。
    • 解决:改用 su -sudo -i 切换 root。

  2. 软件源同步延迟
    • 执行 sudo apt clean 清理缓存后重试。
    • 检查镜像站状态(如 USTC Status)。


六、推荐镜像站列表

镜像站 地址 特点
中科大 http://mirrors.ustc.edu.cn 更新快,支持非自由固件
阿里云 http://mirrors.aliyun.com 分布式架构,稳定性高
清华大学 https://mirrors.tuna.tsinghua.edu.cn 教育网优化,支持 HTTPS
华为云 http://mirrors.huaweicloud.com 企业级服务,带宽充足

引用:


总结
快速换源:推荐使用 DEB822 格式或一键脚本。
稳定性优先:中科大、清华源综合表现最佳。
安全性建议:优先启用 HTTPS 并定期更新密钥。









在Debian 12(代号Bookworm)中更换APT国内镜像源的具体步骤如下:


1. 备份原始源列表

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

2. 编辑源列表文件
使用nano或vim:

sudo nano /etc/apt/sources.list

3. 替换为国内镜像源(任选一个)

清华大学镜像源

# 默认注释源码镜像以提高更新速度,需源码可取消注释
deb 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 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/ bookworm main contrib non-free non-free-firmware

阿里云镜像源

deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware

华为云镜像源

deb https://repo.huaweicloud.com/debian/ bookworm main contrib non-free non-free-firmware
deb https://repo.huaweicloud.com/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://repo.huaweicloud.com/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://repo.huaweicloud.com/debian-security/ bookworm-security main contrib non-free non-free-firmware

4. 更新软件包列表

sudo apt update && sudo apt upgrade -y

⚠️ 注意事项

  1. 选择镜像:使用pingcurl -I测试镜像响应速度(如 ping mirrors.aliyun.com
  2. 非自由软件:如果需闭源驱动,确保包含 non-freenon-free-firmware
  3. 格式检查:换源后若报错,检查是否遗漏空格或拼写错误
  4. 企业环境:内网用户需配置代理或使用内部镜像

附:一键换源脚本(清华源)

sudo sed -i "s@http://.*.debian.org@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo apt update
























Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐