介绍
我这里以vmware虚拟机虚化出来一台Debian 11版本的Linux系统,然后进行的说明。
配置源
APT源分为两种,一种为本地镜像APT源,一种为外网APT源。本地镜像APT源,就是使用镜像中自带的APT包进行安装,而外网就不用说了,直接通过网络进行下载。
配置本地镜像APT源
1、挂载镜像
配置本地镜像源,需要先将Debian镜像的文件,挂载到系统中,这里也可以理解为U盘,插入到接口一样,都是为了让系统能够识别到镜像文件。
2、识别镜像
Debian上可以使用apt-cdrom管理APT本地源,它会确定镜像的结构,并纠正一些可能的错误和验证索引文件。
root@test:~# apt-cdrom ident
可以从上图中看到,默认情况下会帮我们将镜像文件挂载到/media/cdrom挂载点上。
3、添加镜像源
通过apt-cdrom识别出源后,可以通过参数add将其添加到源文件中,它会在/etc/apt/source.list中新增一条刚刚识别的源信息。
root@test:~# apt-cdrom add
4、配置源
由于Debian的配置问题,添加完镜像源后,还需要配置源,才能够正常使用。如果不配置,则使用apt会报错。
root@test:~# vim /etc/apt/sources.list
配置源为可信的,并将其他源都注释掉
deb [trusted=yes] cdrom:[Debian GNU/Linux 11.4.0 _Bullseye_ - Official amd64 DVD Binary-1 20220709-10:33]/ bullseye contrib main
5、使用
至此,镜像源就已经配置好,可以正常使用apt-get或apt命令来安装依赖了。
root@test:~# apt install vim
配置外网APT源
1、挑选外网源
配置外网源之前,我们首先要确定要配置的外网Debian源,国内常用的有腾迅软件源、阿里开源镜像等,我这里以配置阿里Debian源为例。
首先打开阿里开源镜像站官网,然后找到Debian系统,点进去后就有各个版本的配置方法。
2、备份本地文件
在找到源后,先备份/etc/apt/source.list文件,避免在源配置后不可用,想还原到之前时,找不到原来的文件。
root@test:~# cp /etc/apt/sources.list /etc/apt/sources.list.20220901
3、新增源
编辑源配置文件
root@test:~# vim /etc/apt/sources.list
新增阿里Debian源,注释掉其他源记录,新增后,保存并退出。
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
4、使用
至此,外网源配置完成,可以正常使用apt-get或apt命令来安装依赖了。
获取最新软件更新
root@test:~# apt update
可以看到,已经在使用网络检查更新了。
评论区