mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
translated
This commit is contained in:
parent
8beb39da90
commit
eaad9b2750
@ -7,16 +7,16 @@
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Understanding Ubuntu’s Repository System
|
||||
了解 Ubuntu 的软件存储库系统
|
||||
======
|
||||
|
||||
When you start using Ubuntu or an Ubuntu-based distribution, soon you’ll find yourself using apt commands to install software like this:
|
||||
当你开始使用 Ubuntu 或者其它基于 Ubuntu 的发行版时,你很快就会学会使用 `apt` 命令安装软件包:
|
||||
|
||||
```
|
||||
sudo apt install package_name
|
||||
```
|
||||
|
||||
You’ll probably also install additional software using the 3-step PPA command:
|
||||
你可能还会使用这三条 PPA 命令安装其它软件:
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:PPA_Name/ppa
|
||||
@ -24,112 +24,112 @@ 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.
|
||||
**如果你了解了 Ubuntu 软件存储库的运行机制,你就会很清楚这些问题的根源是什么**,进而对症下药地给出处理方式。
|
||||
|
||||
You might find all this information in fragments on It’s FOSS and various forums. But the fragmented information is not easy to understand.
|
||||
在 It's FOSS 或者其它类似的论坛上,你可以找到很多相关的零散内容,但那些碎片化的信息并不能让你对其产生一个全面的理解。
|
||||
|
||||
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).
|
||||
本文的内容适用于 Linux Mint、Elementary OS 以及其它基于 Ubuntu 的发行版(Debian 或许也适用)。
|
||||
|
||||
> 📋 This is intended for end users, not developers. I will not show you how to package an application for Ubuntu. You’ll get the necessary knowledge for maintaining your system’s repository sources.
|
||||
> 本文主要面向终端用户而不是开发者,我只会介绍维护系统软件存储库所需要的知识,不会展示如何在 Ubuntu 中打包应用程序。
|
||||
|
||||
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.
|
||||
Ubuntu 通过软件存储库为用户提供软件。软件存储库中包含了各种不同类型的软件包以及它们的元数据文件,元数据文件中记录了软件包的信息,包括软件包名称、版本号、软件包描述和软件存储库名称等。
|
||||
|
||||
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.
|
||||
[这篇文章](https://itsfoss.com/package-manager/)详细介绍了软件包管理器的工作原理,欢迎查阅。
|
||||
|
||||
### Chapter 2: Ubuntu’s Default Repositories
|
||||
### Ubuntu 的默认软件存储库
|
||||
|
||||
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:
|
||||
每个 Ubuntu 版本都有自己的一组四个官方存储库:
|
||||
|
||||
- **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.
|
||||
- **Main** – Canonical 支持的免费开源软件
|
||||
- **Universe** – 社区维护的免费开源软件
|
||||
- **Restricted** – 设备的专有驱动程序
|
||||
- **Multiverse** – 受版权或法律问题限制的软件
|
||||
|
||||
### Chapter 3: Understanding sources.list
|
||||
### 了解 `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.
|
||||
`sources.list` 是 Ubuntu 软件存储库机制的一个组成部分。`sources.list` 文件中存在的错误条目常常是引发一些与更新问题的根本原因。
|
||||
|
||||
This is why it is important to understand it.
|
||||
因此,了解 `sources.list` 很重要。
|
||||
|
||||
Sources.list is basically a text file that contains the repository details. Each uncommented line represents a separate repository.
|
||||
`sources.list` 是一个记录了软件存储库信息的文本文件,每一行未被注释的内容都代表一个单独的软件存储库。
|
||||
|
||||
![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.
|
||||
但这些内容需要遵循特定的格式,并且不应出现重复的行。[这篇文章](https://itsfoss.com/sources-list-ubuntu/)中介绍了 `sources.list` 的更多详细内容。
|
||||
|
||||
### Chapter 3: Going in-depth with PPA
|
||||
### 深入了解 PPA
|
||||
|
||||
Though Snaps are pushed by Ubuntu a lot these days, PPAs are still a reliable way to get newer software in Ubuntu.
|
||||
尽管 Ubuntu 最近在大力推广 Snap,但 PPA 仍然是获取 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'.
|
||||
然而很多 Ubuntu 用户都只是刻板地直接运行上面的三条命令来使用 PPA,自然很容易会遇到诸如“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.
|
||||
[这篇文章](https://itsfoss.com/ppa-guide/)是一篇深入详尽的 PPA 指南。
|
||||
|
||||
### 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.
|
||||
除了默认软件存储库和 PPA,你还可以从第三方软件存储库中添加软件。比如 Brave 浏览器、Docker 等软件都专门为 Ubuntu 提供了软件存储库。
|
||||
|
||||
Understand the mechanism of using external repositories.
|
||||
你可以通过[这篇文章](https://itsfoss.com/adding-external-repositories-ubuntu/)了解使用外部软件存储库的机制。
|
||||
|
||||
### 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.
|
||||
现在你已经了解了底层机制,现在可以熟悉一下在使用 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.
|
||||
在某些情况下,可能是网络连接的问题,但也有可能是因为你自行添加了某些软件存储库,或者 `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.
|
||||
检查输出结果的最后几行,它会给出错误信息(也就是以 E: 开头的行)。有了错误信息之后,就可以开始故障排除了。
|
||||
|
||||
#### 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.
|
||||
如果 Ubuntu 用户未检查其 Ubuntu 版本是否存在 PPA,盲目向系统中添加 PPA 时,就很可能会遇到这样的错误。
|
||||
|
||||
```
|
||||
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.
|
||||
原因很可能就是这个软件存储库没有针对所使用的 Ubuntu 版本进行配置。
|
||||
|
||||
#### Problem With MergeList
|
||||
#### MergeList 问题
|
||||
|
||||
If you see an error like this:
|
||||
如果你看到这样的错误:
|
||||
|
||||
```
|
||||
E:Encountered a section with no Package: header,
|
||||
@ -137,29 +137,29 @@ E:Problem with MergeList /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_prec
|
||||
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.
|
||||
好吧!严格来说,这不是一个错误。它只是一个警告。但它仍然很常见,可能会给许多 Ubuntu 新用户带来麻烦。
|
||||
|
||||
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.
|
||||
出现这个问题是因为 `sources.list` 文件中有重复的条目。解决办法是将所有重复的行删除至只保留一行。
|
||||
|
||||
### 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.
|
||||
在读完这篇文章后,希望你对 Ubuntu 的软件存储库机制能有更深入的了解。下一次当你遇到错误并寻找解决方案时,你就更有可能理解发生了什么。
|
||||
|
||||
Next, you should learn to use the apt command for package management. There's more than just apt install or apt remove.
|
||||
接下来,你应该学会使用 `apt` 的各种命令管理软件包,不仅仅只是 `apt install` 或 `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.
|
||||
由于 Ubuntu 比以往任何时候都更推崇 Snap,所以你也应该学习一些必要的 Snap 命令。
|
||||
|
||||
Flatpak applications are also gaining popularity and you may come across them sooner or later.
|
||||
Flatpak 应用程序也越来越受欢迎,你也很可能会接触到它们。
|
||||
|
||||
💬 I hope you enjoyed learning about the repository mechanism and has more clarity on package management. Do share your thoughts in the comment section.
|
||||
希望你喜欢学习软件存储库的机制,并对软件包管理有更清晰的认识。欢迎在评论区分享你的想法。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user