如何在 Debian 9 上配置 sources.list

這是關於如何在 Debian 9 上配置 source.list 文件的簡要說明,代號為stretch。 Debian 是最受歡迎的 Linux 發行版之一,它的大部分優勢來自於 Debian 包管理的核心—— 易於. Debian 中的所有內容,無論是應用程序還是任何其他組件 – 都內置在一個包中,然後該包安裝到您的系統上(由安裝程序或您自己安裝)。

了解 APT 和 sources.list

Debian 及其衍生產品的包管理器是恰當的。 APT 代表 Advanced Package Tool,是一組用於管理 Debian 軟件包以及安裝在 Debian 系統上的應用程序的工具。 APT 可以:

  • 安裝應用程序
  • 刪除應用程序
  • 更新應用程序
  • 修復損壞的包等

另請閱讀 : 如何離線安裝 Debian 軟件包

APT 能夠解決依賴問題並從指定的包存儲庫中檢索請求的包。 它將包的實際安裝和刪除委託給 dpkg. APT 主要由命令行工具使用,但也有 GUI 您可以使用的可用工具。

文件 /etc/apt/sources.list 在 Debian 中被 Apt 用作其操作的一部分。 該文件包含一個列表 “來源” 從中可以獲得包。 此文件中的條目通常遵循此格式。

deb https://site.example.com/debian distribution component1 component2 component3
deb-src https://site.example.com/debian distribution component1 component2 component3

上面顯示的條目是虛構的,不應使用。 以下是拆分為不同部分時該文件的內容:

存檔類型:

每行的第一個條目 – 德布 或者 deb-src 代表檔案的類型。

  • 德布 表示提供的 URL 包含預編譯的包。 這些是使用 apt-get 或 aptitude 等包管理器時默認安裝的包。
  • deb-src 用 Debian 控製文件 (.dsc) 和包含打包程序所需更改的 diff.gz 指示源包。

存儲庫網址:

該行的下一個條目是指向下載包的存儲庫的 URL。 您可以從以下位置找到 Debian 存儲庫軟件包的主列表 Debian Worldwide sources.list 鏡像.

分配:

“發行版”可以是發行代號/別名(傑西, 伸展, 剋星, sid) 或發布類別(舊的穩定版、穩定版、測試版、不穩定版)。 如果您要跟踪發布類,請使用類名,如果您想跟踪 Debian 點發布,請使用代號。

零件

通常有三個組件可以在 Debian 上使用,即:

  • main – 這包含屬於 Debian 發行版的軟件包。 這些軟件包符合 DFSG 標準。
  • contrib – 這裡的包符合 DFSG 但包含不在主存儲庫中的包。
  • non-free – 這包含不符合 DFSG 的軟件包。

Debian 9 上的完整 sources.list 文件如下所示:

deb https://deb.debian.org/debian stretch main
deb-src https://deb.debian.org/debian stretch main

deb https://deb.debian.org/debian stretch-updates main
deb-src https://deb.debian.org/debian stretch-updates main

deb https://security.debian.org/debian-security/ stretch/updates main
deb-src https://security.debian.org/debian-security/ stretch/updates main

然後要擁有 contrib 和 non-free 組件,在 main 之後添加 contrib non-free ,如下所示:

deb https://deb.debian.org/debian stretch main contrib non-free
deb-src https://deb.debian.org/debian stretch main contrib non-free

deb https://deb.debian.org/debian stretch-updates main contrib non-free
deb-src https://deb.debian.org/debian stretch-updates main contrib non-free

deb https://security.debian.org/debian-security/ stretch/updates main contrib non-free
deb-src https://security.debian.org/debian-security/ stretch/updates main contrib non-free

對 sources.list 文件進行更改後,您必須運行以下命令:

$ sudo apt-get update

這將確保您的 apt 索引同步。 然後您可以從存儲庫安裝新軟件包。

添加自定義存儲庫

在文件上添加自定義和第三方存儲庫並不總是可取的 /etc/apt/sources.list。 相反,您可以在 /etc/apt/sources.list.d 目錄下創建一個文件。 為了 example,要從其上游存儲庫在 Debian 9 上安裝 docker,您將執行以下操作:

$ sudo vim /etc/apt/sources.list

添加內容:

deb https://apt.dockerproject.org/repo debian-stretch main

然後,您可以繼續更新 apt-cache 並從中安裝 docker 包。 這是添加任何其他第三方存儲庫的推薦方法。

導入 apt 密鑰

使用 apt 和 sources.list 存儲庫時,有時需要導入 gpg 密鑰。 這通常使用命令 apt-key 完成,其語法為。

# apt-key adv --keyserver  <server-address>--recv-keys  <key-id>

作為 example, 要下載 docker 存儲庫 gpg 密鑰,您將運行:

# apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

然後

# apt-get update &&  apt-get install docker-engine

一般來說,使用sources.list 文件相對容易。 您唯一需要熱衷的是放置正確的發行版。 如果在穩定安裝中添加包含不穩定包的 sid 存儲庫,則最終可能會破壞系統或遇到許多未解決的依賴項。