如何更改 Debian 源为更快的镜像源?

Debian 是一个广泛使用的操作系统之一, 而它最吸引人的方面之一就是其极为庞大和丰富的软件仓库。这是作为一个基于 Linux 系统的优势,同时也是开源社区的共同汇聚成果。但不幸的是,由于恶劣的网络下载速度或过低的带宽,有时在安装、升级或安装软件包时,访问官方源就会变得非常缓慢,这对于使用 Debian 的人来说是一个令人头疼的问题。

好消息是,Debian 是高度定制化的操作系统,其系统源地址也是可以用者根据自己的实际情况而进行定制设置的。在这篇文章中,我们将介绍如何将 Debian 系统的源更改为一个更快的镜像源。

首先,我们需要打开 Terminal 终端并切换到超级用户权限状态。您可以通过以下命令来打开 Terminal:

```terminal Ctrl + Alt + T ```

然后应使用以下命令获得 root 权限:

```terminal su ```

此时,您需要输入超级用户的密码以获得新的权限。输入密码后,您将进入新的控制台。

接下来,您需要找到目前使用的源文件。Debian 默认情况下使用的源文件是 /etc/apt/sources.list。现在可以使用 vim 或 gedit 等编辑器打开该文件,并对该文件进行备份:

```terminal cp /etc/apt/sources.list /etc/apt/sources.list.backup ```

这将创建 sources.list 文件的备份,以便我们可以在需要的情况下进行还原。

现在打开 sources.list 文件并用以下的 command 进行编辑:

```terminal vi /etc/apt/sources.list ```

注意:这里使用的是 vi 编辑器,如果你不熟悉 vi 编辑器,建议使用 gedit 编辑器。

然后您将看到类似以下的内容:

```terminal deb http://http.debian.net/debian stable main contrib non-free deb-src http://http.debian.net/debian stable main contrib non-free

deb http://http.debian.net/debian-security/ stable/updates main contrib non-free deb-src http://http.debian.net/debian-security/ stable/updates main contrib non-free

deb http://http.debian.net/debian-stable/ stable-updates main contrib non-free deb-src http://http.debian.net/debian-stable/ stable-updates main contrib non-free ```

这些都是默认源地址,为了将其改为更快的镜像源,您可以在以下的网站中查找一个适合自己的自选镜像源。

镜像站网站:

http://www.debian.org/mirror/list

在该网站中,您可以找到一系列可供选择的 Internet 镜像源。在中国大陆地区,中科大、阿里云和清华镜像站都有提供 Debian 镜像源服务。因此您可以选择其中一个来进行使用。选择镜像源后,只需将源内容复制并粘贴到最上面的 default 里面。

例如:在中科大镜像站中找到了镜像地址:

```terminal deb http://mirrors.ustc.edu.cn/debian/ stretch main non-free contrib deb-src http://mirrors.ustc.edu.cn/debian/ stretch main non-free contrib deb http://mirrors.ustc.edu.cn/debian/ stretch-updates main non-free contrib deb-src http://mirrors.ustc.edu.cn/debian/ stretch-updates main non-free contrib deb http://mirrors.ustc.edu.cn/debian/ stretch-backports main non-free contrib deb-src http://mirrors.ustc.edu.cn/debian/ stretch-backports main non-free contrib deb http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main non-free contrib deb-src http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main non-free contrib ```

debian更换源

然后我们只需将 /etc/apt/sources.list 文件中的所有默认源地址更改为我们刚才选择的源地址即可。

最后,保存文件并退出编辑器,使用以下命令更新软件包列表:

```terminal apt-get update ```

命令完成后,我们将看到新的源地址加入,这意味着系统现在将更新下载软件包的位置切换为新的源地址,此时您将更快速地更新系统包、升级软件等。

本文介绍了如何将 Debian 系统的源更改为更快的镜像源。如果您经常使用 Debian,您将会发现该技巧非常有帮助。你可以找到一个更接近自己的区域,从而更快的获得 Debian 的新特性。