Armbian换国内源

2020年7月24日 38541点热度 7人点赞 28条评论

什么是国内源

在探讨什么是国内源之前,首先要弄清楚,什么是“软件源”。“源”,顾名思义就是来源的意思。“软件源”就是软件的来源,也就是就是在安装软件时,apt从哪里获取软件包。

一般来说,软件源在Armbian(或者说整个Debian系)中的体现是/etc/apt/目录下的sources.list和/etc/apt/sources.list .d/目录下以“.list”结尾的一系列文件(如下列图片)。

Armbian换国内源
刚装好的Armbian系统在/etc/apt/目录下只有sources.list和sources.list.d目录
Armbian换国内源
刚装好的Armbian系统在/etc/apt/sources.list.d/目录下只有armbian.list

这些文件存储着一系列的网址(见下图),即我们说的“软件源”。

Armbian换国内源
sources.list和其他list包含一系列的网址,即软件源

因为Armbian的软件源默认是官方源,官方的服务器在海外,所以下载速度特别慢,经常出现断连和不稳定的情况。国内的一些高校和公司为了保证科研和生产的稳定,会自建官方源的镜像站以提高下载速度和提升连接稳定性,这就是我们说的“国内源”。所以为了避免在安装软件时出现各种奇奇怪怪的错误,笔者通常在装完Armbian后,会把软件源换成国内的。

Armbian怎么换国内源

1、查看Armbian版本

用SSH连接Armbian设备后,注意看自己的登录后的欢迎界面:看一下框里面是stretch还是buster或者是其他(如下图)。下面两张图分别是stretch和buster版本,不同版本所用的源是不一样的。换源时要对应起来。

Armbian换国内源
笔者的玩客云是stretch版本
笔者的斐讯N1是buster版本

2、确定要换的Armbian国内源

一般来说国内常用的Armbian源有:

清华源官网:https://mirrors.tuna.tsinghua.edu.cn/

中科大源官网:https://mirrors.ustc.edu.cn/

如需要其他软件源,请自行搜索。笔者用的是清华源,所以下文以清华源为例进行演示。

3、开始换源——以清华源为例

首先要明确一点,我们所说的Armbian换国内源其实就是指修改/etc/apt/下的sources.list/etc/apt/sources.list.d/下的armbian.list这两个文件。一定不要弄错了。

①修改sources.list

用PuTTY或Xshell通过SSH连接Armbian设备后,执行下面的命令:

nano /etc/apt/sources.list

如果你没有安装nano那么执行下面的命令:

vi /etc/apt/sources.list
Armbian换国内源

按Delete删除sources.list里面的所有内容。然后打开上文提到的Debian源直达链接(Armbian是Debian的一个分支,所以不要疑惑为什么这里是Debian而不是Armbian),如下图所示:

Armbian换国内源

选择你的Armbian版本(stretch/buster/其他),红框内容会随之变化,把红框内的内容复制下来(如果你没有什么特殊需求,注释掉的内容无需取消注释),粘贴到sources.list里面并保存。

Armbian换国内源
按Ctrl+X然后选择Y,按回车确认即可保存(nano)

如果你是用vi(vim)编辑sources.list的,在用Delete把原来的内容删除后,输入”i“进入编辑模式,然后粘贴清华源,再按Esc退出编辑模式,再输入”:wq“即可保存并退出。

为了方便读者,我把清华Debian源的stretch版本和buster版本粘到下面,方便各位使用。

stretch版本:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free

buster版本:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free

②修改armbian.list

armbian.list在/etc/apt/sources.list.d/目录(该目录通常用来存放第三方的软件源)下,在PuTTY或Xshell里输入如下命令:

nano /etc/apt/sources.list.d/armbian.list

删掉原有的内容,然后根据自己的Armbian版本(stretch/buster/其他)替换成以下内容:

stretch版本:

deb https://mirrors.tuna.tsinghua.edu.cn/armbian stretch main stretch-utils stretch-desktop

buster版本:

deb https://mirrors.tuna.tsinghua.edu.cn/armbian buster main buster-utils buster-desktop

如果你是其他版本,请将上面链接中表示版本的stretch/buster等字眼对应替换成你的版本如bullseye等。

最重要一步(非常重要)

当完成以上所有操作后,你的Armbian就换成了清华源,但是还需要执行下面的命令使之生效

apt-get update

这个命令会访问软件源列表里的每个网址,然后更新软件列表索引并保存在本地。如果在安装软件A的过程中用到了软件B,那么就会自动到软件列表里拉取。如果我们没有执行该命令,就可能会导致找不到相关的软件包而出错。所以在安装新的软件之前(宝塔、nginx、php、mysql等)都要先执行这个操作(不过也不用太频繁地执行该命令,一次安装多个软件,执行一次即可,太频繁了也没什么可以更新的)。执行完之后再装软件一般就不会报错了(当然,该出错的还是会错)。

其他问题

如果在执行apt-get update后出现“Could not resolve host:xxxxx”的问题,则要修改DNS,请参考这篇文章

麦克斯和雪莉

非常规文科生

文章评论

  • 123

    请问有没有视频教程

    2021年9月4日
  • 求助

    你好,可以加Q吗?我的玩客云出了点莫名其妙的问题,求助 :cry:
    邮箱是我QQ

    2021年9月30日
  • 3538368581

    Traceback (most recent call last):
    File "setup.py", line 19, in <module>
    from setuptools import Extension, setup, find_packages
    ImportError: No module named setuptools
    =================================================
    Pillow installation failed.

    2021年10月1日
    • 麦克斯和雪莉

      @3538368581 换清华源update一下再装宝塔,你可以先试一试,如果还是不行,再试一试这俩命令apt install python-setuptools或apt install python3-setuptools

      2021年10月2日
  • 3538368581

    你好,我又来了,可以加q吗?我问题有点多 :lol:
    Debian怎么换yum源,安装宝塔少了点东西,apt了没有,只能yum好像,或者大佬指点一下别的方法也行

    2021年10月3日
    • 麦克斯和雪莉

      @3538368581 你换清华源了吗,如果换源后apt还是不能安装我说的那俩软件之一的话,看看你的Linux时区是否是对的,如果不对更改时区后再尝试apt安装一下

      2021年10月3日
  • 3538368581

    你好,依旧不行 :cry:

    2021年10月4日
    • 麦克斯和雪莉

      @3538368581 兄弟,你是什么设备,armbian是什么版本,软件源是什么,以及你进行了什么操作,出现了什么错误,你说一下啊

      2021年10月4日
  • 3538368581

    玩客云armbian5.67下载宝塔5.9有一堆问题,软件园是清华源。然后宝塔安装软件也一堆问题 :cry:

    2021年10月5日
  • cc

    博主你好,出现如下报错,请教如何处理。我查阅了网上的资料,修改时间,修改证书验证都没有效果。不好意思啊照着教程都弄不好。。。
    server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

    2021年10月16日
  • cc

    搞好了,竟然是因为清华源拉了,最后用的国外源配置好的软件

    2021年10月16日
  • 翁MIX

    请教一下为什么在用清华源的时候用https执行update就会报错,而用http就不会报错,系统版本Debian buster,是不是清华源的问题
    Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate. Could not handshake: Error in the certificate verification.

    2022年1月25日
    • 麦克斯和雪莉

      @翁MIX SSL证书的问题,清华源最近不是很稳定,可以先用中科大的源

      2022年1月31日
  • 翁MIX

    所有的镜像源都是同步的吗,还是说有哪个服务器是最先更新的,如果有的话方便提供一下吗

    2022年1月31日
    • 麦克斯和雪莉

      @翁MIX 不完全同步,理论上官方的是最新的,其他都是官方的镜像,如果清华的不稳定,建议先用中科大的,算是国内比较好用的

      2022年1月31日
  • 翁MIX

    能提供官方的镜像源吗,我网络是可以的,官方源是deb.debian.org么,还是哪一个

    2022年1月31日
  • 123

    换源没有权限怎么办?

    2022年12月11日
  • 太难了

    博主 我换了好多源为啥下载都是巨慢无比啊 下载个docker 一晚上都没下载下来 :lol:

    2023年1月9日
  • G'et

    把所有的https改为http, '记住是所有的’

    2023年5月4日
  • 希晨

    博主您好,我在执行完buster的步骤之后,最后一步apt-get update的时候在下载的时候有Err,能帮我看看嘛?具体如下:
    Get:8 https://mirrors.tuna.tsinghua.edu.cn/debian buster InRelease [122 kB]
    Get:9 https://mirrors.tuna.tsinghua.edu.cn/debian buster-updates InRelease [56.6 kB]
    Ign:10 https://mirrors.tuna.tsinghua.edu.cn/debian buster-backports InRelease
    Ign:11 https://mirrors.tuna.tsinghua.edu.cn/armbian buster InRelease
    Err:12 https://mirrors.tuna.tsinghua.edu.cn/debian buster-backports Release
    404 Not Found [IP: 101.6.15.130 443]
    Err:13 https://mirrors.tuna.tsinghua.edu.cn/armbian buster Release
    404 Not Found [IP: 101.6.15.130 443]
    Get:14 https://mirrors.tuna.tsinghua.edu.cn/debian buster/main armhf Packages [7,706 kB]
    Get:15 https://mirrors.tuna.tsinghua.edu.cn/debian buster/main Translation-en [5,969 kB]
    Get:16 https://mirrors.tuna.tsinghua.edu.cn/debian buster/main armhf Contents (deb) [36.9 MB]
    Get:17 https://mirrors.tuna.tsinghua.edu.cn/debian buster/contrib armhf Packages [40.1 kB]
    其他的全都是Get,正常

    2024年4月19日
  • Kevin

    有些源似乎失效了。。

    2024年6月24日