---
category: help
layout: help
mirrorid: debian
---

# Debian 软件仓库镜像使用帮助

<form class="form-inline">
<div class="form-group">
	<label>是否使用 HTTPS</label>
	<select id="http-select" class="form-control content-select" data-target="#content-0,#content-1">
	  <option data-http_protocol="https://" selected>是</option>
	  <option data-http_protocol="http://">否</option>
	</select>
</div>
</form>


<form class="form-inline">
<div class="form-group">
	<label>是否使用 sudo</label>
	<select id="sudo-select" class="form-control content-select" data-target="#content-0,#content-1">
	  <option data-sudo="sudo " selected>是</option>
	  <option data-sudo="">否</option>
	</select>
</div>
</form>



一般情况下，将 `/etc/apt/sources.list` 文件中 Debian 默认的源地址 `http://deb.debian.org/` 替换为镜像地址即可。

Debian Buster 以上版本默认支持 HTTPS 源。如果遇到无法拉取 HTTPS 源的情况，请先使用 HTTP 源并安装：



{% raw %}
<script id="template-0" type="x-tmpl-markup">
{{sudo}}apt install apt-transport-https ca-certificates
</script>
{% endraw %}

<p></p>

<pre>
<code id="content-0" data-template="#template-0" data-select="#http-select,#sudo-select">
</code>
</pre>




<form class="form-inline">
<div class="form-group">
  <label>Debian 版本：</label>
    <select id="select-1-0" class="form-control content-select" data-target="#content-1">
      <option data-release_name="bullseye" data-security="-security" data-is_sid="" data-has_backports="" selected>Debian 11 (bullseye)</option>
      <option data-release_name="bookworm" data-security="-security" data-is_sid="" data-has_backports="">Debian 12 (bookworm)</option>
      <option data-release_name="sid" data-security="-security" data-is_sid="# " data-has_backports="# ">sid</option>
      <option data-release_name="testing" data-security="-security" data-is_sid="" data-has_backports="">testing</option>
      <option data-release_name="buster" data-security="/updates" data-is_sid="" data-has_backports="">Debian 10 (buster)</option>
      <option data-release_name="stretch" data-security="/updates" data-is_sid="" data-has_backports="">Debian 9 (stretch)</option>
      <option data-release_name="jessie" data-security="/updates" data-is_sid="" data-has_backports="# ">Debian 8 (jessie)</option>
    </select>
</div>
</form>

<form class="form-inline">
<div class="form-group">
  <label>启用源码镜像：</label>
    <select id="select-1-1" class="form-control content-select" data-target="#content-1">
      <option data-enable_source="# " selected>否</option>
      <option data-enable_source="">是</option>
    </select>
</div>
</form>

<form class="form-inline">
<div class="form-group">
  <label>使用官方安全更新软件源：</label>
    <select id="select-1-2" class="form-control content-select" data-target="#content-1">
      <option data-security_mirror="# " data-security_official="" selected>是</option>
      <option data-security_mirror="" data-security_official="# ">否</option>
    </select>
</div>
</form>

{% raw %}
<script id="template-1" type="x-tmpl-markup">
# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
deb {{http_protocol}}{{mirror}}/ {{release_name}} main contrib non-free
{{enable_source}}deb-src {{http_protocol}}{{mirror}}/ {{release_name}} main contrib non-free

{{is_sid}}deb {{http_protocol}}{{mirror}}/ {{release_name}}-updates main contrib non-free
{{is_sid}}{{enable_source}}deb-src {{http_protocol}}{{mirror}}/ {{release_name}}-updates main contrib non-free

{{is_sid}}{{has_backports}}deb {{http_protocol}}{{mirror}}/ {{release_name}}-backports main contrib non-free
{{is_sid}}{{has_backports}}{{enable_source}}deb-src {{http_protocol}}{{mirror}}/ {{release_name}}-backports main contrib non-free

{{security_mirror}}{{is_sid}}deb {{http_protocol}}{{mirror}}-security {{release_name}}{{security}} main contrib non-free
{{security_mirror}}{{is_sid}}{{enable_source}}deb-src {{http_protocol}}{{mirror}}-security {{release_name}}{{security}} main contrib non-free

{{security_official}}{{is_sid}}deb {{http_protocol}}security.debian.org/debian-security {{release_name}}{{security}} main contrib non-free
{{security_official}}{{is_sid}}{{enable_source}}deb-src {{http_protocol}}security.debian.org/debian-security {{release_name}}{{security}} main contrib non-free
</script>
{% endraw %}

<p></p>

<pre>
<code id="content-1" data-template="#template-1" data-select="#http-select,#sudo-select,#select-1-0,#select-1-1,#select-1-2">
</code>
</pre>


为了方便快速配置，此处一并附上了 debian-security 的配置，一般来说，镜像站会同时提供 debian-security，截至写文档时，DNUI、HIT 与 NYIST 未提供该镜像，为了更准确的信息您可以前往 [Debian Security 帮助](/help/debian-security) 确认。

不过，一般来说，为了更及时地获得安全更新，不推荐使用镜像站安全更新软件源，因为镜像站往往有同步延迟。参考 https://www.debian.org/security/faq.en.html#mirror

> The purpose of security.debian.org is to make security updates available as quickly and easily as possible.
>
> Encouraging the use of unofficial mirrors would add extra complexity that is usually not needed and that can cause frustration if these mirrors are not kept up to date.

### Connection reset by peer

在 apt 2.1.9 及以后的版本中，apt 的 HTTP Pipelining 特性与 Nginx 服务器疑似存在一定的不兼容问题，可能导致高带宽从镜像站下载大量软件包
（例如系统升级）时出现偶发的 Connection reset by peer 错误
（详见 [Debian bug #973581](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=973581)）。

目前，用户可以通过关闭 HTTP Pipelining 特性解决此问题。
如果需要关闭，可以在使用 `apt` 命令时加上 `-o Acquire::http::Pipeline-Depth=0` 参数，
或使用以下命令将相关设置加入 apt 系统配置中：

```bash
echo "Acquire::http::Pipeline-Depth \"0\";" > /etc/apt/apt.conf.d/99nopipelining
```

