Merge pull request #29847 from HankChow/translating

translated
This commit is contained in:
geekpi 2023-08-10 08:53:17 +08:00 committed by GitHub
commit 5e8d28ea9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 179 additions and 179 deletions

View File

@ -1,179 +0,0 @@
[#]: subject: "Understanding Ubuntus Repository System"
[#]: via: "https://itsfoss.com/ubuntu-repository-mechanism/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lkxed"
[#]: translator: "HankChow"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Understanding Ubuntus Repository System
======
When you start using Ubuntu or an Ubuntu-based distribution, soon youll find yourself using apt commands to install software like this:
```
sudo apt install package_name
```
Youll 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, youll 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 wont understand what causes the problem and how it was fixed._
But **if you understand the repository mechanism in Ubuntu, youll understand the root cause of the problem** and fix it accordingly.
You might find all this information in fragments on Its 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).
> 📋 This is intended for end users, not developers. I will not show you how to package an application for Ubuntu. Youll get the necessary knowledge for maintaining your systems repository sources.
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.
![][1]
This article explains the working of the package manager in a bit more detail. Do check it out.
### Chapter 2: Ubuntus 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.
### 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][2]
But these entries follow a specific format and should not have duplicate entries. Read more about them in the article below.
### 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.
### 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.
### 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][3]
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.
#### 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.
#### 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.
### 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.
You may also go a bit into detail about package management.
Since Ubuntu is pushing for Snaps more than ever, learn the essential Snap commands.
Flatpak applications are also gaining popularity and you may come across them sooner or later.
💬 I hope you enjoyed learning about the repository mechanism and has more clarity on package management. Do share your thoughts in the comment section.
--------------------------------------------------------------------------------
via: https://itsfoss.com/ubuntu-repository-mechanism/
作者:[Abhishek Prakash][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lkxed/
[1]: https://itsfoss.com/content/images/2023/04/image.png
[2]: https://itsfoss.com/content/images/2023/07/image-4.png
[3]: https://itsfoss.com/content/images/2023/07/failed-to-download-repository-information-1.png

View File

@ -0,0 +1,179 @@
[#]: subject: "Understanding Ubuntus Repository System"
[#]: via: "https://itsfoss.com/ubuntu-repository-mechanism/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lkxed"
[#]: translator: "HankChow"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
了解 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 软件存储库的运行机制,你就会很清楚这些问题的根源是什么**,进而对症下药地给出处理方式。
在 It's FOSS 或者其它类似的论坛上,你可以找到很多相关的零散内容,但那些碎片化的信息并不能让你对其产生一个全面的理解。
因此我写出了这篇文章,以便让你全面了解软件存储库是如何运作的。
本文的内容适用于 Linux Mint、Elementary OS 以及其它基于 Ubuntu 的发行版Debian 或许也适用)。
> 本文主要面向终端用户而不是开发者,我只会介绍维护系统软件存储库所需要的知识,不会展示如何在 Ubuntu 中打包应用程序。
我们会先从关键部分开始,了解软件包管理器和软件存储库的基本概念。这可以为了解它们的底层运作方式奠定基础。
### 什么是包管理器?
简单地说,包管理器就是让用户在操作系统上安装、移除、升级、配置、管理软件包的工具。
Ubuntu 通过软件存储库为用户提供软件。软件存储库中包含了各种不同类型的软件包以及它们的元数据文件,元数据文件中记录了软件包的信息,包括软件包名称、版本号、软件包描述和软件存储库名称等。
软件包管理器与元数据进行交互,并在你的系统上创建本地的元数据缓存。当你需要安装软件时,软件包管理器会引用这些缓存来获取信息,通过互联网连接到对应的存储库下载软件包,然后再将软件包安装到系统上。
![][1]
[这篇文章](https://itsfoss.com/package-manager/)详细介绍了软件包管理器的工作原理,欢迎查阅。
### Ubuntu 的默认软件存储库
在上一节中,你可能已经对软件存储库有了一些认识。
你可能已经猜到,没有哪个软件存储库会包含所有软件包。因为软件包会被分类放置在不同的软件存储库中,这样就可以方便地启用或禁用部分软件存储库。
每个 Ubuntu 版本都有自己的一组四个官方存储库:
- **Main** Canonical 支持的免费开源软件
- **Universe** 社区维护的免费开源软件
- **Restricted** 设备的专有驱动程序
- **Multiverse** 受版权或法律问题限制的软件
### 了解 `sources.list`
`sources.list` 是 Ubuntu 软件存储库机制的一个组成部分。`sources.list` 文件中存在的错误条目常常是引发一些与更新问题的根本原因。
因此,了解 `sources.list` 很重要。
`sources.list` 是一个记录了软件存储库信息的文本文件,每一行未被注释的内容都代表一个单独的软件存储库。
![sources.list in Ubuntu][2]
但这些内容需要遵循特定的格式,并且不应出现重复的行。[这篇文章](https://itsfoss.com/sources-list-ubuntu/)中介绍了 `sources.list` 的更多详细内容。
### 深入了解 PPA
尽管 Ubuntu 最近在大力推广 Snap但 PPA 仍然是获取 Ubuntu 最新软件的一个可靠途径。
然而很多 Ubuntu 用户都只是刻板地直接运行上面的三条命令来使用 PPA自然很容易会遇到诸如“repository does not have release file”这样的问题。
[这篇文章](https://itsfoss.com/ppa-guide/)是一篇深入详尽的 PPA 指南。
### 添加外部软件存储库
除了默认软件存储库和 PPA你还可以从第三方软件存储库中添加软件。比如 Brave 浏览器、Docker 等软件都专门为 Ubuntu 提供了软件存储库。
你可以通过[这篇文章](https://itsfoss.com/adding-external-repositories-ubuntu/)了解使用外部软件存储库的机制。
### 排查常见错误
现在你已经了解了底层机制,现在可以熟悉一下在使用 Ubuntu 时可能遇到的典型更新错误了。
当你看到出现错误之后,你会得到一些关于它的根本原因的提示。在了解根本原因后,你就能知道某个解决方案是如何解决问题的了。
这就是本文的目的。让你充分了解软件包管理系统的底层知识,从而避免常见错误或者直接有效修复这些错误。
**你不仅要知其然,还要知其所以然。**
#### 下载软件存储库信息失败
如果遇到了这种情况,这仅仅是排查过程的开始。
![Failed to download repository information][3]
在某些情况下,可能是网络连接的问题,但也有可能是因为你自行添加了某些软件存储库,或者 `sources.list` 中的条目有误。
这个时候应该在终端中尝试刷新软件包缓存。
```
sudo apt update
```
检查输出结果的最后几行,它会给出错误信息(也就是以 E: 开头的行)。有了错误信息之后,就可以开始故障排除了。
#### 软件存储库中没有发布文件
如果 Ubuntu 用户未检查其 Ubuntu 版本是否存在 PPA盲目向系统中添加 PPA 时,就很可能会遇到这样的错误。
```
E: The repository http://ppa.launchpad.net/numix/ppa/ubuntu focal Release does not have a Release file.
```
原因很可能就是这个软件存储库没有针对所使用的 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.
```
这表明第二行中提到的缓存文件已经损坏。对应的解决方法是清空缓存并重试。
#### 目标软件包被多次配置
好吧!严格来说,这不是一个错误。它只是一个警告。但它仍然很常见,可能会给许多 Ubuntu 新用户带来麻烦。
这是一个能让你把新学到的知识用在这里的好例子。
出现这个问题是因为 `sources.list` 文件中有重复的条目。解决办法是将所有重复的行删除至只保留一行。
### 继续学习
在读完这篇文章后,希望你对 Ubuntu 的软件存储库机制能有更深入的了解。下一次当你遇到错误并寻找解决方案时,你就更有可能理解发生了什么。
接下来,你应该学会使用 `apt` 的各种命令管理软件包,不仅仅只是 `apt install``apt remove`
你还可以详细了解一下关于软件包管理的其它知识。
由于 Ubuntu 比以往任何时候都更推崇 Snap所以你也应该学习一些必要的 Snap 命令。
Flatpak 应用程序也越来越受欢迎,你也很可能会接触到它们。
希望你喜欢学习软件存储库的机制,并对软件包管理有更清晰的认识。欢迎在评论区分享你的想法。
--------------------------------------------------------------------------------
via: https://itsfoss.com/ubuntu-repository-mechanism/
作者:[Abhishek Prakash][a]
选题:[lkxed][b]
译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lkxed/
[1]: https://itsfoss.com/content/images/2023/04/image.png
[2]: https://itsfoss.com/content/images/2023/07/image-4.png
[3]: https://itsfoss.com/content/images/2023/07/failed-to-download-repository-information-1.png