了解 Ubuntu 的软件存储库系统
软件库 存储库
![](/data/attachment/album/202308/11/112409wi0g83krczglar3r.jpg)



> 
> 了解 Ubuntu 软件仓库系统的基本机制，更好地处理软件包管理问题，避免常见的更新错误。
> 
> 
> 


当你开始使用 Ubuntu 或者其它基于 Ubuntu 的发行版时，你很快就会学会使用 `apt` 命令安装软件包：



```
sudo apt install package_name

```

你可能还会使用这三条 PPA 命令安装其它软件：



```
sudo add-apt-repository ppa:PPA_Name/ppa
sudo apt update
sudo apt install package_from_ppa

```

但当你添加一些外部的软件存储库时，很可能会遇到一些更新错误。


尽管你可以在互联网上搜索到同样的报错以及对应的解决方案，*但在大多数情况下，你并不知道这些错误为什么会出现，也不知道它们是怎么被解决的。*


**如果你了解了 Ubuntu 软件存储库的运行机制，你就会很清楚这些问题的根源是什么**，进而对症下药地给出处理方式。


在技术论坛上，你可以找到很多相关的零散内容，但那些碎片化的信息并不能让你对其产生一个全面的理解。


因此我写出了这篇文章，以便让你全面了解软件存储库是如何运作的。


本文的内容适用于 Linux Mint、Elementary OS 以及其它基于 Ubuntu 的发行版（Debian 或许也适用）。



> 
> 本文主要面向终端用户而不是开发者，我只会介绍维护系统软件存储库所需要的知识，不会展示如何在 Ubuntu 中打包应用程序。
> 
> 
> 


我们会先从关键部分开始，了解软件包管理器和软件存储库的基本概念。这可以为了解它们的底层运作方式奠定基础。


### 1、什么是包管理器？


简单地说，包管理器就是让用户在操作系统上安装、移除、升级、配置、管理软件包的工具。


Ubuntu 通过软件存储库为用户提供软件。软件存储库中包含了各种不同类型的软件包以及它们的元数据文件，元数据文件中记录了软件包的信息，包括软件包名称、版本号、软件包描述和软件存储库名称等。


软件包管理器与元数据进行交互，并在你的系统上创建本地的元数据缓存。当你需要安装软件时，软件包管理器会引用这些缓存来获取信息，通过互联网连接到对应的存储库下载软件包，然后再将软件包安装到系统上。


![](/data/attachment/album/202308/11/112455zyyfv9c45m9evwy9.png)


下面这篇文章详细介绍了软件包管理器的工作原理，欢迎查阅。



> 
> **[Linux 上的软件包管理器](https://itsfoss.com/package-manager/)**
> 
> 
> 


### 2、Ubuntu 的默认软件存储库


在上一节中，你可能已经对软件存储库有了一些认识。


你可能已经猜到，没有哪个软件存储库会包含所有软件包。因为软件包会被分类放置在不同的软件存储库中，这样就可以方便地启用或禁用部分软件存储库。


每个 Ubuntu 版本都有自己的一组四个官方存储库：


* **Main** – Canonical 支持的自由开源软件
* **Universe** – 社区维护的自由开源软件
* **Restricted** – 设备的专有驱动程序
* **Multiverse** – 受版权或法律问题限制的软件


下面这篇文章介绍了如何在 Ubuntu 中启用 Universe 和 Multiverse 软件存储库。



> 
> **[如何启用 Universe 和 Multiverse 软件存储库](https://itsfoss.com/ubuntu-repositories/)**
> 
> 
> 


### 3、了解 sources.list


`sources.list` 是 Ubuntu 软件存储库机制的一个组成部分。`sources.list` 文件中存在的错误条目常常是引发一些与更新问题的根本原因。


因此，了解 `sources.list` 很重要。


`sources.list` 是一个记录了软件存储库信息的文本文件，每一行未被注释的内容都代表一个单独的软件存储库。


![sources.list in Ubuntu](/data/attachment/album/202308/11/112455r736qt16xqk6xkni.png)


但这些内容需要遵循特定的格式，并且不应出现重复的行。下面这篇文章中介绍了 `sources.list` 的更多详细内容。



> 
> **[sources.list 的用法](https://itsfoss.com/sources-list-ubuntu/)**
> 
> 
> 


### 4、深入了解 PPA


尽管 Ubuntu 最近在大力推广 Snap，但 PPA 仍然是获取 Ubuntu 最新软件的一个可靠途径。


然而很多 Ubuntu 用户都只是刻板地直接运行上面的三条命令来使用 PPA，自然很容易会遇到诸如“repository does not have release file”这样的问题。


下面这篇文章是一篇深入详尽的 PPA 指南。



> 
> **[PPA 详尽指南](https://itsfoss.com/ppa-guide/)**
> 
> 
> 


### 5、添加外部软件存储库


除了默认软件存储库和 PPA，你还可以从第三方软件存储库中添加软件。比如 Brave 浏览器、Docker 等软件都专门为 Ubuntu 提供了软件存储库。


你可以通过下面这篇文章了解使用外部软件存储库的机制。



> 
> **[通过外部存储库安装软件](https://itsfoss.com/adding-external-repositories-ubuntu/)**
> 
> 
> 


### 6、排查常见错误


现在你已经了解了底层机制，现在可以熟悉一下在使用 Ubuntu 时可能遇到的典型更新错误了。


当你看到出现错误之后，你会得到一些关于它的根本原因的提示。在了解根本原因后，你就能知道某个解决方案是如何解决问题的了。


这就是本文的目的。让你充分了解软件包管理系统的底层知识，从而避免常见错误或者直接有效修复这些错误。


**你不仅要知其然，还要知其所以然。**


#### 下载软件存储库信息失败


如果遇到了这种情况，就可以开始调查了。


![Failed to download repository information](/data/attachment/album/202308/11/112456emqtzqyz4y8ymxyj.png)


在某些情况下，可能是网络连接的问题，但也有可能是因为你自行添加了某些软件存储库，或者 `sources.list` 中的条目有误。


这个时候应该在终端中尝试刷新软件包缓存。



```
sudo apt update

```

检查输出结果的最后几行，它会给出错误信息（也就是以 “E:” 开头的行）。有了错误信息之后，就可以开始故障排除了。


#### 软件存储库中没有发布文件


如果 Ubuntu 用户未检查某个 PPA 是否支持其 Ubuntu 版本，就盲目向系统中添加该 PPA 时，就很可能会遇到这样的错误。



```
E: The repository ‘http://ppa.launchpad.net/numix/ppa/ubuntu focal Release’ does not have a Release file.

```

原因很可能就是这个软件存储库没有针对所使用的 Ubuntu 版本进行配置。


下面这篇文章对此做了详细解释。



> 
> **[软件存储库中没有发布文件](https://itsfoss.com/repository-does-not-have-release-file-error-ubuntu/)**
> 
> 
> 


#### MergeList 问题


如果你看到这样的错误：



```
E:Encountered a section with no Package: header,
E:Problem with MergeList /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_precise_universe_binary-i386_Packages,
E:The package lists or status file could not be parsed or opened.

```

这表明第二行中提到的缓存文件已经损坏。对应的解决方法是清空缓存并重试。


下面这篇文章对此做了详细解释。



> 
> **[MergeList 问题](https://itsfoss.com/how-to-fix-problem-with-mergelist/)**
> 
> 
> 


#### 目标软件包被多次配置


好吧！严格来说，这不是一个错误。它只是一个警告。但它仍然很常见，可能会给许多 Ubuntu 新用户带来麻烦。


这是一个能让你把新学到的知识用在这里的好例子。


出现这个问题是因为 `sources.list` 文件中有重复的条目。解决办法是将所有重复的行删除至只保留一行。


下面这篇文章对此做了详细解释。



> 
> **[目标软件包被多次配置](https://itsfoss.com/fixing-target-packages-configured-multiple-times/)**
> 
> 
> 


### 7、继续学习


在读完这篇文章后，希望你对 Ubuntu 的软件存储库机制能有更深入的了解。下一次当你遇到错误并寻找解决方案时，你就更有可能理解发生了什么。


接下来，你应该学会使用 `apt` 的各种命令管理软件包，不仅仅只是 `apt install` 或 `apt remove`。



> 
> **[apt 命令详尽指南](https://itsfoss.com/apt-command-guide/)**
> 
> 
> 


你还可以详细了解一下关于软件包管理的其它知识。



> 
> **[完全指南：在 Ubuntu 安装和删除软件](https://itsfoss.com/remove-install-software-ubuntu/)**
> 
> 
> 


由于 Ubuntu 比以往任何时候都更推崇 Snap，所以你也应该学习一些必要的 Snap 命令。



> 
> **[完全指南：在 Ubuntu 上使用 Snap 安装包](https://itsfoss.com/use-snap-packages-ubuntu-16-04/)**
> 
> 
> 


Flatpak 应用程序也越来越受欢迎，你也很可能会接触到它们。



> 
> **[在 Ubuntu 上安装和使用 Flatpak](https://itsfoss.com/flatpak-ubuntu/)**
> 
> 
> 


希望你喜欢学习软件存储库的机制，并对软件包管理有更清晰的认识。欢迎在评论区分享你的想法。


*（题图：MJ/6878226c-f6b0-40e7-aae7-d64932b36464）*




---


via: <https://itsfoss.com/ubuntu-repository-mechanism/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lkxed](https://github.com/lkxed/) 译者：[HankChow](https://github.com/HankChow) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

When you start using Ubuntu or an Ubuntu-based distribution, soon you’ll find yourself using apt commands to install software like this:

`sudo apt install package_name`


You’ll probably also install additional software using the 3-step PPA command:

```
sudo add-apt-repository ppa:PPA_Name/ppa
sudo apt update
sudo apt install package_from_ppa
```


And when you start adding random external repositories, you’ll encounter update errors sooner or later.

Now, you can search for the error on the internet and perhaps fix it as well. *Most of the time, you won’t understand what causes the problem and how it was fixed.*

But **if you understand the repository mechanism in Ubuntu, you’ll understand the root cause of the problem** and fix it accordingly.

You might find all this information in fragments on It’s FOSS and various forums. But the fragmented information is not easy to understand.

Hence, I created this page to give you a comprehensive understanding of how the repository system works.

This guide also benefits the users of Linux Mint, elementary OS and other distributions based on Ubuntu (and perhaps Debian).

Let's start with the essentials first. Understands the basic concept of the package manager and the repositories. This will build a foundation for you to understand how things work underneath.

## Chapter 1: What is a Package Manager?

In simpler words, a package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system.

Ubuntu provides the software through repositories. The repositories contain software packages of different kinds. They also have metadata files that contain information about the packages such as the name of the package, version number, description of package and the repository name etc.

The package manager interacts with the metadata and creates a local metadata cache on your system. When you ask it to install a software, the package manager refers to this cache to get the information and then uses the internet to connect to the appropriate repository and downloads the package first before installing it on your system.

![](https://itsfoss.com/content/images/2023/04/image.png)

This article explains the working of the package manager in a bit more detail. Do check it out.

[What is a Package Manager in Linux?Learn about packaging system and package managers in Linux. You’ll learn how do they work and what kind of package managers available.](https://itsfoss.com/package-manager/)![](https://itsfoss.com/content/images/wordpress/2020/10/linux-package-manager-explanation.png)


![](https://itsfoss.com/content/images/wordpress/2020/10/linux-package-manager-explanation.png)

## Chapter 2: Ubuntu’s Default Repositories

From the previous section, you have some idea of the repositories.

You may have guessed that there is not a single repository that contains all the packages. Why not? Because it is categorized to have the packages in different repositories so that they can be enabled or disabled accordingly.

Each Ubuntu version has its own official set of four repositories:

**Main**– Canonical-supported free and open-source software.**Universe**– Community-maintained free and open-source software.**Restricted**– Proprietary drivers for devices.**Multiverse**– Software restricted by copyright or legal issues.

[How to Enable Universe and Multiverse Repositories in UbuntuThis detailed article tells you about various repositories like universe, multiverse in Ubuntu and how to enable or disable them.](https://itsfoss.com/ubuntu-repositories/)![](https://itsfoss.com/content/images/wordpress/2019/03/ubuntu-repositories.png)


![](https://itsfoss.com/content/images/wordpress/2019/03/ubuntu-repositories.png)

## Chapter 3: Understanding sources.list

The sources.list is an integral part of Ubuntu's repository mechanism. Several update-related issues find their root cause in the incorrect entries in the sources.list file.

This is why it is important to understand it.

Sources.list is basically a text file that contains the repository details. Each uncommented line represents a separate repository.

![sources.list in Ubuntu](https://itsfoss.com/content/images/2023/07/image-4.png)

But these entries follow a specific format and should not have duplicate entries. Read more about them in the article below.

[What is the Use of sources.list File in Ubuntu Linux?Understanding the concept of sources.list in Ubuntu will help you understand and fix common update errors in Ubuntu.](https://itsfoss.com/sources-list-ubuntu/)![](https://itsfoss.com/content/images/2022/12/sources-lits-file-ubuntu.png)


![](https://itsfoss.com/content/images/2022/12/sources-lits-file-ubuntu.png)

## Chapter 3: Going in-depth with PPA

Though Snaps are pushed by Ubuntu a lot these days, PPAs are still a reliable way to get newer software in Ubuntu.

Many Ubuntu users blindly run three commands to use the PPA and naturally end up with issues like 'repository does not have release file'.

This is an in-depth and one-of-a-kind guide on PPA. It will improve your knowledge tremendously.

[Understanding PPA in Ubuntu Linux [Ultimate Guide]An in-depth article that covers almost all the questions around using PPA in Ubuntu and other Linux distributions.](https://itsfoss.com/ppa-guide/)![](https://itsfoss.com/content/images/2023/05/Understanding-ppa-in-ubuntu.png)


![](https://itsfoss.com/content/images/2023/05/Understanding-ppa-in-ubuntu.png)

## Chapter 4: Adding External Repositories

Apart from the default repositories and PPAs, you will also add software from their party repositories. Softwares like Brave browser, Docker and many more provide dedicated repositories for Ubuntu.

Understand the mechanism of using external repositories.

[Installing Packages From External Repositories in UbuntuLearn the logic behind each step you have to follow for adding an external repository in Ubuntu and installing packages from it.](https://itsfoss.com/adding-external-repositories-ubuntu/)![](https://itsfoss.com/content/images/wordpress/2021/08/adding-external-repository-ubuntu.png)


![](https://itsfoss.com/content/images/wordpress/2021/08/adding-external-repository-ubuntu.png)

## Chapter 5: Troubleshooting Common Errors

Now that you are familiar with the underlying mechanism, it's time to get familiar with the typical update errors you might encounter while using Ubuntu.

When you see go through the error, you may start getting the hint about the root cause. And when you go through the root cause, you will understand how the specific solution fixes it.

And that's the aim of this page. To give you enough under-the-hood knowledge on the package management system so that you can avoid common errors or effectively fix them.

**You'll understand the why along with the how.**

### Failed to Download Repository Information

If you encounter this error, it's just the beginning of your investigation.

![Failed to download repository information](https://itsfoss.com/content/images/2023/07/failed-to-download-repository-information-1.png)

While the internet connection could be the issue in some cases, chances are that you have an issue because of some repository you added or wrong entries in the sources.list.

You should jump into the terminal and (try to) refresh the package cache.

`sudo apt update`


Look at the last few lines of the output. It will give you the error message (lines starting with E:). When you have the error message, your troubleshooting begins.

### Repository Does Not Have a Release File

A common error Ubuntu users encounter while blindly adding PPAs to the system without checking if the PPA exists for their Ubuntu version or not.

`E: The repository ‘http://ppa.launchpad.net/numix/ppa/ubuntu focal Release’ does not have a Release file.`


Let me give you a hint. The repository is not configured for the Ubuntu version being used.

[What to do When You See “Repository does not have a release file” Error in UbuntuOne of the several ways of installing software in Ubuntu is by using PPA or adding third-party repositories. A few magical lines give you easy access to a software or its newer version that is not available by default in Ubuntu. All thing looks well and good until you get](https://itsfoss.com/repository-does-not-have-release-file-error-ubuntu/)![](https://itsfoss.com/content/images/wordpress/2020/05/Repository-does-not-have-a-release-file.png)


![](https://itsfoss.com/content/images/wordpress/2020/05/Repository-does-not-have-a-release-file.png)

### Problem With MergeList

If you see an error like this:

```
E:Encountered a section with no Package: header,
E:Problem with MergeList /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_precise_universe_binary-i386_Packages,
E:The package lists or status file could not be parsed or opened.
```


It indicates that somehow the cached file mentioned in the second line got corrupted. The fix is to empty the cache and repopulate it.

[How To Fix Ubuntu Update Error: Problem With MergeListOne of the most common error a user encounters while updating is Problem with MergeList. The error could be encountered while using both Ubuntu Update Manager and using the sudo apt-get update in terminal. The complete error looks something like this: E:Encountered a section with no Packag…](https://itsfoss.com/how-to-fix-problem-with-mergelist/)![](https://itsfoss.com/content/images/wordpress/2012/09/Error.jpg)


![](https://itsfoss.com/content/images/wordpress/2012/09/Error.jpg)

### Target Packages is configured multiple times

Alright! Technically, not an error. It's just a warning. But it is still quite common and could trouble many new Ubuntu users.

This is a good example for putting your newly acquired knowledge here.

There are duplicate entries in the sources.list files and that's causing the issue. The solution is to delete all the duplicate lines keeping just one.

[[Solved] Target Packages is configured multiple times ErrorSeeing repository configured multiple times error while updating your system with apt update command? Here’s what you can do about it.](https://itsfoss.com/fixing-target-packages-configured-multiple-times/)![](https://itsfoss.com/content/images/wordpress/2021/12/troubleshooting-target-configured-multiple-times-ubuntu.png)


![](https://itsfoss.com/content/images/wordpress/2021/12/troubleshooting-target-configured-multiple-times-ubuntu.png)

## Continue Learning

I hope you have a slightly better understanding of the repository mechanism in Ubuntu. The next time you encounter an error and come across a solution, you are more likely to understand what's going on.

Next, you should learn to use the apt command for package management. There's more than just apt install or apt remove.

[Using apt Commands in Linux [Ultimate Guide]This guide shows you how to use apt commands in Linux with examples so that you can manage packages effectively.](https://itsfoss.com/apt-command-guide/)![](https://itsfoss.com/content/images/wordpress/2017/07/apt-commands-example.png)


![](https://itsfoss.com/content/images/wordpress/2017/07/apt-commands-example.png)

You may also go a bit into detail about package management.

[How To Install And Remove Software In Ubuntu [Complete Guide]Brief: This detailed guide shows you various ways to install applications on Ubuntu Linux, and it also demonstrates how to remove installed software from Ubuntu. When you switch to Linux, the experience could be overwhelming at the start. Even basic things like installing applications on Ubuntu…](https://itsfoss.com/remove-install-software-ubuntu/)![](https://itsfoss.com/content/images/wordpress/2022/12/remove-install-software-in-ubuntu-guide.png)


![](https://itsfoss.com/content/images/wordpress/2022/12/remove-install-software-in-ubuntu-guide.png)

Since Ubuntu is pushing for Snaps more than ever, learn the essential Snap commands.

[Using Snap Packages In Ubuntu & Other Linux [Complete Guide]Ubuntu’s new universal package Snaps are now everywhere. You should learn the essential snap commands to master this new packaging system.](https://itsfoss.com/use-snap-packages-ubuntu-16-04/)![](https://itsfoss.com/content/images/wordpress/2016/04/Essential-Snap-Commands.jpeg)


![](https://itsfoss.com/content/images/wordpress/2016/04/Essential-Snap-Commands.jpeg)

Flatpak applications are also gaining popularity and you may come across them sooner or later.

[Install and Use Flatpak on UbuntuUbuntu may come with Snap by default but you could still enjoy the Flatpak universal packages on it.](https://itsfoss.com/flatpak-ubuntu/)![](https://itsfoss.com/content/images/2023/06/install-flatpak-ubuntu.png)


![](https://itsfoss.com/content/images/2023/06/install-flatpak-ubuntu.png)

💬 I hope you enjoyed learning about the repository mechanism and has more clarity on package management. Do share your thoughts in the comment section.