From 8ce541dd42a21daaf5c2d507c5ff1b1f4380561c Mon Sep 17 00:00:00 2001 From: perfiffer <36044385+perfiffer@users.noreply.github.com> Date: Tue, 27 Jul 2021 08:00:15 +0800 Subject: [PATCH] translated (#22683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 译文提交 * translated * translated * translated * translated * delete sources --- ...0719 Linux package managers- dnf vs apt.md | 232 ------------------ ...0719 Linux package managers- dnf vs apt.md | 212 ++++++++++++++++ 2 files changed, 212 insertions(+), 232 deletions(-) delete mode 100644 sources/tech/20210719 Linux package managers- dnf vs apt.md create mode 100644 translated/tech/20210719 Linux package managers- dnf vs apt.md diff --git a/sources/tech/20210719 Linux package managers- dnf vs apt.md b/sources/tech/20210719 Linux package managers- dnf vs apt.md deleted file mode 100644 index e000804d37..0000000000 --- a/sources/tech/20210719 Linux package managers- dnf vs apt.md +++ /dev/null @@ -1,232 +0,0 @@ -[#]: subject: (Linux package managers: dnf vs apt) -[#]: via: (https://opensource.com/article/21/7/dnf-vs-apt) -[#]: author: (Seth Kenlon https://opensource.com/users/seth) -[#]: collector: (lujun9972) -[#]: translator: (perfiffer ) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) - -Linux package managers: dnf vs apt -====== -Package managers do the same general things—installing, managing, and -uninstalling applications—but they don't do everything the same. -![Gift box opens with colors coming out][1] - -There are many ways to [get applications onto a Linux system][2]. Some, like Flatpak and containers, are new. Others, like DEB and RPM, are classic formats that have withstood the test of time. - -There isn't a universal installer for any operating system. Today, all major OSes use a mix of app stores (both first and third party), drag-and-drop installation, and installation wizards because there are innumerable developers delivering software. Different developers have different requirements for the code they deliver, and this informs the installation method they each choose. - -Linux pioneered the concept of a _package manager_, a command to install, manage, and uninstall applications. Two common package manager commands are `apt` and `dnf`. The `apt` command manages DEB packages, while `dnf` manages RPM packages. The two are not strictly exclusive of one another in theory, although in practice, a Linux distribution generally uses one or the other. It's theoretically possible to run both on one system, but package installations would overlap, versioning would be difficult, and the commands would be redundant to one another. However, if you work in a mixed Linux environment, interacting with workstations running one distribution and servers running another, you may need to know both. - -### Searching for applications - -Before you can install an application with a package manager, you need to know the package's name. Usually, the application name and the package name are the same. The process to verify the name of the package you want to install is exactly the same on `dnf` and `apt`: - - -``` -$ sudo dnf search zsh -====== Name Exactly Matched: zsh ====== -zsh.x86_64 : Powerful interactive shell -[...] -``` - -With `apt`: - - -``` -$ sudo apt search zsh -Sorting... Done -Full Text Search... Done -csh/stable 20110502-4+deb10u1 amd64 -  Shell with C-like syntax - -ddgr/stable 1.6-1 all -  DuckDuckGo from the terminal - -direnv/stable 2.18.2-2 amd64 -  Utility to set directory specific environment variables - -draai/stable 20180521-1 all -  Command-line music player for MPD -[...] -``` - -To get relevant results from `apt` earlier in the search, you can use [regex][3]: - - -``` -apt search ^zsh -Sorting... Done -Full Text Search... Done -zsh/stable 5.7.1-1 amd64 -  shell with lots of features -[...] -``` - -### Finding an application's package - -Some commands come bundled with other commands, all in one package. When that happens, you can use your package manager to learn which package provides what you need. The `dnf` and `apt` commands diverge on how they search for this kind of metadata. - -On `dnf`: - - -``` -$ sudo dnf provides pgrep -procps-ng-3.3.15-6.el8.x86_64 : System and process monitoring utilities -Repo        : baseos -Matched from: -Filename    : /usr/bin/pgrep -``` - -The `apt` command uses a subcommand, `apt-file`. To use `apt-file`, you must first install it and then prompt it to update its cache: - - -``` -$ sudo apt install apt-file -Reading package lists... Done -Building dependency tree       -Reading state information... Done -The following additional packages will be installed: -  libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl -The following NEW packages will be installed: -  apt-file libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl -0 upgraded, 5 newly installed, 0 to remove and 14 not upgraded. -Need to get 297 kB of archives. -After this operation, 825 kB of additional disk space will be used. -Do you want to continue? [Y/n] y - -$ sudo apt-file update -[...] -``` - -You can use `apt-file` to search for a command. You can cast a very wide net by just searching for the command, but if you happen to know the command's expected path, it's more accurate: - - -``` -$ sudo apt-file search /usr/bin/pgrep -pgreplay: /usr/bin/pgreplay               -procps: /usr/bin/pgrep -``` - -### Installing applications - -Installing applications is essentially identical with `apt` and `dnf`: - - -``` -`$ sudo apt install zsh` -``` - -With `dnf`, you can install a single package using the same option: - - -``` -`$ sudo dnf install zsh` -``` - -Many RPM-based distributions feature _installation groups_, which collect sometimes superficially related applications into one easily installable target. For instance, the [Design Suite][4] group in Fedora contains popular creative applications. Many artists who want one creative application are likely to want similar applications, and installing the whole group is an easy and quick way to get a sensible start on building a digital studio. You can view available groups with `group list` (use `-v` to see the group names without spaces): - - -``` -$ sudo dnf group list -v -[...] -Available Groups: -   Container Management (container-management) -   RPM Development Tools (rpm-development-tools) -   Design Suite (design-suite) -   Development Tools (development) -[...] -``` - -Install an RPM group using the `group install` subcommands: - - -``` -`$ sudo dnf group install design-suite` -``` - -You can use the `@` notation to reduce typing: - - -``` -`$ sudo dnf install @design-suite` -``` - -### Upgrading applications - -One advantage of using a package manager is that it is aware of _all_ the applications it has ever installed. That means you don't have to go hunting for updated versions of applications. Instead, you can tell your package manager to scan for updates. - -The subcommands used by `dnf` and `apt` are slightly different. Because `apt` keeps a cache of information that requires regular updating, it uses the `upgrade` subcommand for application updates: - - -``` -`$ sudo apt upgrade` -``` - -By contrast, `dnf` updates metadata every time you use the command, so the `update` and `upgrade` subcommands are interchangeable: - - -``` -`$ sudo dnf upgrade` -``` - -This is the same as: - - -``` -`$ sudo dnf update` -``` - -### Removing applications - -If you've ever tried to remove an application manually on any platform, then you know there are inevitably leftover files, such as preference files or assets or icons, scattered all around your hard drive after you remove the application. Yet another advantage to using a package manager is that your package manager knows _every single file_ installed with a package: - - -``` -`$ sudo dnf remove zsh` -``` - -The `remove` subcommand is also used for `apt`: - - -``` -`$ sudo apt remove zsh` -``` - -Removing a package with `apt` doesn't remove modified user configuration files, in case you removed the package by accident. If you want `apt` to remove an application _and_ its configuration files, use `purge` on an application you've previously removed: - - -``` -`$ sudo apt purge zsh` -``` - -Both `apt` and `dnf` (even with `purge`) don't remove data or configuration files in your home directory. To remove data from your home directory, you must do it manually (it's usually found in `~/.config` and `~/.local`). - -### Learning package management - -Whether your Linux distribution of choice favors `apt` or `dnf`, the commands' purposes are broadly identical. They help you install, update, and remove packages. These two, being the most common package managers, largely mirror one another's most important syntactical elements, so switching between them is pretty easy. - -Each has some advanced features, such as repository management, that diverge substantially, but those tend not to be run as frequently as the classic sequence of `search` and `install`. - -Regardless of which package manager you use more often, you can download our [apt cheat sheet][5] and [dnf cheat sheet][6] so that you have the most important syntax close at hand when you need it the most. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/21/7/dnf-vs-apt - -作者:[Seth Kenlon][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/seth -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_gift_giveaway_box_520x292.png?itok=w1YQhNH1 (Gift box opens with colors coming out) -[2]: https://opensource.com/article/18/1/how-install-apps-linux -[3]: https://opensource.com/article/18/5/getting-started-regular-expressions -[4]: https://labs.fedoraproject.org/en/design-suite/ -[5]: https://opensource.com/downloads/apt-cheat-sheet -[6]: https://opensource.com/downloads/dnf-cheat-sheet diff --git a/translated/tech/20210719 Linux package managers- dnf vs apt.md b/translated/tech/20210719 Linux package managers- dnf vs apt.md new file mode 100644 index 0000000000..8f44323f69 --- /dev/null +++ b/translated/tech/20210719 Linux package managers- dnf vs apt.md @@ -0,0 +1,212 @@ +[#]: subject: (Linux package managers: dnf vs apt) +[#]: via: (https://opensource.com/article/21/7/dnf-vs-apt) +[#]: author: (Seth Kenlon https://opensource.com/users/seth) +[#]: collector: (lujun9972) +[#]: translator: (perfiffer ) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) + +Linux 包管理器: dnf 和 apt +====== +包管理器提供同样的功能-安装,管理和删除应用-但是它们还是有一些不一样的地方。 +![Gift box opens with colors coming out][1] + +有多种方式 [在Linux系统上获取一个应用][2]。例如,最新的Flatpak 和容器,另外,还有 DEB 和 RPM,是一直以来经受住了考验的方式。 + +对于所有的操作系统来说,目前并不存在一种通用的应用安装程序。今天,因为有无数的开发者发布软件,这导致了大部分的操作系统使用了应用商店(包括第一方和第三方),拖拽式的安装方式,还有安装向导。不同的开发者对于他们发布的代码有不同的需求,这直接导致了他们所选择的安装方式的不同。 + +Linux 开创了一种通过命令行安装,管理,卸载应用的包管理器理念。`apt` 和 `dnf` 就是两种较为常见的包管理器。`apt` 命令是用来管理 DEB 格式的包,`dnf` 命令是用来管理 RPM 格式的包。这两种包管理器在理论上并不是完全互斥的,尽管在实际的实践中,Linux 发行版通常只会使用到其中的一种。理论上,这两种命令可以运行在同一个系统上,但是会造成安装包的重叠,版本控制也会更加困难,命令彼此之间是冗余的。然而,如果您是在一个复杂的 Linux 环境下工作,比如您的工作站运行的是一个发行版,同时需要与运行另外一种发行版的服务器进行交互,那么您最好掌握这两种包管理器。 + +### 搜索应用 + +当您通过包管理器安装一个应用时,您需要先知道包的名称。通常,应用的名称和包的名称是一样的。`dnf` 和 `apt` 验证要安装的包名的过程是完全相同的。 + +``` +$ sudo dnf search zsh +====== 名称 精准匹配:zsh ====== +zsh.x86_64 : Powerful interactive shell +``` + +使用 `apt`: + +``` +$ sudo apt search zsh +正在排序... 完成 +全文搜索... 完成 +csh/stable 20110502-4+deb10u1 amd64 +  Shell with C-like syntax + +ddgr/stable 1.6-1 all +  DuckDuckGo from the terminal + +direnv/stable 2.18.2-2 amd64 +  Utility to set directory specific environment variables + +draai/stable 20180521-1 all +  Command-line music player for MPD +[...] +``` + +如果想通过 `apt` 更快的获取相关的搜索结果,您可以使用 [正则表达式][3]: + +``` +apt search ^zsh +正在排序... 完成 +全文搜索... 完成 +zsh/stable 5.7.1-1 amd64 +  shell with lots of features +[...] +``` + +### 查找应用程序包 +在一个包中,有一些命令是与其它命令捆绑在一起的。在这种情况下,您可以通过包管理器去了解哪个包提供了您需要的命令。`dnf` 和 `apt` 命令在如何搜索这类元数据上是有区别的。 + +使用 `dnf`: + +``` +$ sudo dnf provides pgrep +procps-ng-3.3.15-6.el8.x86_64 : System and process monitoring utilities +仓库        : baseos +匹配来源: +文件名    : /usr/bin/pgrep +``` + +`apt` 命令使用子命令,`apt-file`。要使用 `apt-file`,您必须先安装它,然后提示它更新缓存: + +``` +$ sudo apt install apt-file +正在读取软件包列表... 完成 +正在分析软件包的依赖关系树       +正在读取状态信息... 完成 +下列额外的软件包将要被安装: +  libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl +下列【新】软件包将被安装: +  apt-file libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl +升级了 0 个软件包,新安装了 5 个软件包,要卸载 0 个软件包,有 14 个软件包未被升级。 +需要下载 297 kB 的归档。 +解压缩后会消耗 825 kB 的额外空间。 +您想要继续吗? [Y/n] y + +$ sudo apt-file update +[...] +``` + +您可以通过 `apt-file` 搜索命令。您可以使用此命令进行广泛的全局搜索,但假如您知道命令的执行路径,它会更准确: + +``` +$ sudo apt-file search /usr/bin/pgrep +pgreplay: /usr/bin/pgreplay               +procps: /usr/bin/pgrep +``` + +### 安装应用程序 + +使用`apt` 和 `dnf` 安装应用程序基本上是相同的: + +``` +$ sudo apt install zsh +``` + +使用 `dnf`,您可以使用同样的方式来安装一个包: + +``` +$ sudo dnf install zsh +``` + +许多基于RPM的发行版都具有组包安装的特性,这些特性会将具有相关性的应用程序收集到一个易于安装的目标中。例如,Fedora 中的 [Design Suite][4] 组包就包含流行的创造性应用程序。那些想要一个创造性应用程序的“艺术家”可能也想要一个类似的应用程序,选择安装一整个组包是建立一个数据工厂简单而快速的方法。您可以通过 `group list` 来查看可用的组(使用 `-v` 来过滤空格): + +``` +$ sudo dnf group list -v +[...] +可用组: +   Container Management (container-management) +   RPM Development Tools (rpm-development-tools) +   Design Suite (design-suite) +   Development Tools (development) +[...] +``` + +使用 `group install` 子命令安装 RPM 组: + +``` +$ sudo dnf group install design-suite +``` + +您可以使用 `@` 符号来减少输入: + +``` +$ sudo dnf install @design-suite +``` + +### 更新应用程序 + +使用包管理器的一个优点是,它知道所有已经安装的应用。这样您不必去寻找应用程序的更新版本。相反,您可以通过包管理器去获取更新的版本。 + +`dnf` 和 `apt` 使用的子命令略有不同。因为 `apt` 保存了需要定期更新的缓存信息,它使用 `upgrade` 子命令来更新应用程序: + +``` +$ sudo apt upgrade +``` + +相比之下,`dnf` 命令在您每次使用时都会更新元信息,所以 `update` 和 `upgrade` 子命令是可以互换的: + +``` +$ sudo dnf upgrade +``` + +这等同于: + +``` +$ sudo dnf update +``` + +### 删除应用程序 + +如果您曾经尝试在任何一个平台上手动删除一个应用程序,您就会知道,应用程序删除后,在硬盘上会残留各种文件,比如首选项文件、数据或图标。所以包管理器的另一个优点是,包管理器管理着包中安装的每一个文件,可以很方便的删除: + +``` +$ sudo dnf remove zsh +``` + +`remove` 子命令也适用于 `apt`: + +``` +$ sudo apt remove zsh +``` + +使用 `apt` 命令删除一个包并不会删除已修改的用户配置文件,以防您意外删除了包。如果您想通过 `apt` 命令删除一个应用及其配置文件,可以在删除包之前,使用 `purge` 子命令: + +``` +$ sudo apt purge zsh +``` + +`apt` 和 `dnf` 都不会删除家目录中的数据和配置文件(即使使用 `purge` 子命令)。如果想要从家目录中删除数据,您必须手动操作(通常您可以在 `~/.config` 和 `~/.local` 文件中找到)。 + +### 了解包管理 + +无论您选择的发行版支持的是 `apt` 还是 `dnf`,这些命令的用途大致相同。它们可以帮助您安装,更新和删除包。这两种包管理器是目前最通用的包管理器。它们的语法元素在很大程度上是相同的,所以在两者之间切换非常容易。 + +`apt` 和 `dnf` 还有一些高级功能,例如仓库管理,这些功能并不像您使用 `search` 和 `install` 那样频繁。 + +无论您更多的使用哪种包管理器,您都可以下载我们的 [apt 备忘单][5] 和 [dnf 备忘单][6],以便您在最需要的时候可以查询使用语法。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/21/7/dnf-vs-apt + +作者:[Seth Kenlon][a] +选题:[lujun9972][b] +译者:[perfiffer](https://github.com/perfiffer) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/seth +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_gift_giveaway_box_520x292.png?itok=w1YQhNH1 (Gift box opens with colors coming out) +[2]: https://opensource.com/article/18/1/how-install-apps-linux +[3]: https://opensource.com/article/18/5/getting-started-regular-expressions +[4]: https://labs.fedoraproject.org/en/design-suite/ +[5]: https://opensource.com/downloads/apt-cheat-sheet +[6]: https://opensource.com/downloads/dnf-cheat-sheet