如何在Debian 10上配置sources.list

时间:2020-03-05 15:24:56  来源:igfitidea点击:

Debian是有史以来最受欢迎的Linux发行版之一,现在它有了新版本的Debian 10 Buster。

Debian有很多衍生产品,其中最受欢迎的是Ubuntu。

Debian Linux发行版由于其核心的软件包管理APT和软件包格式.deb而被广泛使用。
Debian中的每个应用程序,系统实用程序或者游戏都作为软件包分发。
我们可以使用APT(自动或者手动)将那些软件包安装到系统上。

在本教程中,我们将简要介绍Debian 10的新功能,熟悉APT软件包管理器,并了解如何在Debian 10 Buster上配置它的sources.list文件。

让我们看看有哪些新功能和最重要的更改。

什么是APT管理器及其sources.list

APT是Debian及其衍生版本中使用的软件包管理器。
APT代表Advanced Package Tool,它是一组用于管理Debian软件包的工具,因此可以管理Debian系统上安装的所有应用程序。

APT用于安装,更新或者删除应用程序和软件包。

APT能够解决依赖关系问题并从程序包存储库中检索请求的程序包。
它将软件包的实际安装和删除委托给dpkg低级核心Debian软件包工具。
APT主要由其命令行工具使用,但也有GUI工具可用。

Debian中的文件“ /etc/apt/sources.list”包含可从中获取软件包的“源”列表。
sources.list文件可能会因各种因素而有所不同(安装Debian的介质,从先前发行版更新的介质等)。

这是我们想要在系统上的列表:

$cat /etc/apt/sources.list
deb http://httpredir.debian.org/debian buster main non-free contrib
deb-src http://httpredir.debian.org/debian buster main non-free contrib
deb http://security.debian.org/debian-security buster/updates main contrib non-free
deb-src http://security.debian.org/debian-security buster/updates main contrib non-free

现在,我们将讨论该文件及其不同部分的内容。

Debian sources.list文件的内容和部分

“ sources.list”文件的各节如下:

  • 封存类型
  • 储存库网址
  • 分配
  • Component

现在,我们将详细介绍每个部分。

封存类型

每行deb或者deb-src上的第一项代表存储库档案的类型。

deb表示提供的URL中的存储库包含预编译的软件包。
这些是使用apt-get,aptitude,synaptic等软件包管理器时默认安装的软件包。

deb-src指示源软件包,其中包含Debian控制文件(.dsc)和diff.gz,其中包含打包程序所需的更改。

储存库网址

输入行的下一部分是将从中下载软件包的存储库的URL。
我们可以从Debian Worldwide的sources.list镜像中找到Debian存储库的主要列表。

Distribution

分发可以分别是发布代码名称/别名(jessie,stretch,buster,sid)或者发布类(旧的稳定版,稳定版,测试版,不稳定版)。
如果要跟踪发行版,请使用类名;如果要跟踪Debian发行版,请使用代号。

Component

通常在Debian上可以使用三个组件,分别是:

  • main-它包含Debian发行版中的软件包。这些软件包符合DFSG。
  • contrib-此处的软件包符合DFSG的要求,但是包含的软件包不在主存储库中。
  • 非免费-包含不符合DFSG的软件包。

正如我们在Debian 10 Buster上的以下sources.list文件中看到的那样,我们希望条目列出所有三种组件类型:

deb http://httpredir.debian.org/debian buster main non-free contrib
deb-src http://httpredir.debian.org/debian buster main non-free contrib
deb http://security.debian.org/debian-security buster/updates main contrib non-free
deb-src http://security.debian.org/debian-security buster/updates main contrib non-free

如果sources.list文件不同,则必须在main之后添加contrib和non-free部分,以列出所有软件包。
如果系统上是这种情况,则可以使用nano,vim或者任何其他编辑器编辑文件/etc/apt/sources.list进行更改。
我们将在本文的下一部分中进行介绍。

如果还需要Backports,contrib和非自由组件,请添加buster-backports行。
例如,对于Debian 10 Buster:

deb http://deb.debian.org/debian buster-backports main contrib non-free
deb-src http://deb.debian.org/debian buster-backports main contrib non-free

我们可以改用上述所有URL中的“ https://...”来通过加密的HTTPS连接使用存储库。
(Debian 9 Stretch或者更早版本的用户将需要首先安装apt-transport-https软件包。

如果sources.list包含所有部分,我们可以使用apt-get运行软件包更新。
这将确保apt索引是同步的。
然后,我们可以从存储库中安装新软件包。

$sudo apt-get update
Hit:1 http://security.debian.org/debian-security buster/updates InRelease
Hit:2 http://cdn-fastly.deb.debian.org/debian buster InRelease
Reading package lists... Done

在某些情况下,更新软件包列表时,存储库可能会出错。
在这种情况下,请使用apt而不是apt-get。
apt优先于apt-get进行交互使用。

$sudo apt update
$sudo apt upgrade -y

如果那不能解决问题,那么第二种选择是使用--allow-releaseinfo-change

$sudo apt-get --allow-releaseinfo-change update

添加自定义存储库

并非总是建议在“ /etc/apt/sources.list”文件中添加自定义和第三方存储库。
相反,我们可以在“ /etc/apt/sources.list.d”目录下创建一个文件。
例如,要从其上游存储库在Debian 10 Buster上安装docker-ce,我们将执行以下操作:

$sudo vim /etc/apt/sources.list

添加内容:

deb [arch=amd64] https://download.docker.com/linux/debian buster stable

我们可以使用GNOME工具来编辑sources.list文件。
通过菜单→系统→管理→软件源访问它。

gksu --desktop /usr/share/applications/software-properties.desktop /usr/bin/software-properties-gtk

另一种方法是使用用于添加第三方存储库的apt命令:

$sudo apt-get install software-properties-common
$sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"

然后,我们可以继续更新apt-cache并使用apt-get安装docker-ce软件包。
这是添加任何其他第三方存储库的推荐方法。

我们会注意到这是行不通的,因为系统上没有docker存储库的GPG密钥。
接下来我们将介绍。

导入apt键

在使用apt和sources.list存储库时,有时需要导入GPG密钥。
通常使用以下命令使用apt-key命令来完成此操作:

apt-key adv --keyserver [server-address] --recv-keys [key-id]

或者,我们可以直接下载GPG密钥,然后从当前目录安装它。

例如,要下载Docker存储库GPG密钥,我们将运行:

$curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add 
OK

要测试密钥是否正确安装,请运行以下命令:

$sudo apt-key fingerprint 0EBFCD88
pub   rsa4096 2015-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) 
sub   rsa4096 2015-02-22 [S]

之后,我们将运行:

$sudo apt-get update
$sudo apt-get install docker-ce

在Tor中使用Apt

如果我们担心隐私问题或者不安全的数据传输,则可以在sources.list文件中将Tor与Debian存储库一起使用。
Apt可以通过Tor检索和下载更新。
为此,我们需要安装tor和apt-transport-tor软件包。
然后,我们可以使用Debian提供的官方洋葱服务。

deb tor+http://vwakviie2ienjx6t.onion/debian buster main
deb-src tor+http://vwakviie2ienjx6t.onion/debian buster main
deb tor+http://sgvtcaew4bxjd7ln.onion/debian-security buster/updates main
deb-src tor+http://sgvtcaew4bxjd7ln.onion/debian-security buster/updates main
deb tor+http://vwakviie2ienjx6t.onion/debian buster-updates main
deb-src tor+http://vwakviie2ienjx6t.onion/debian buster-updates main