diff --git a/sources/tech/20200419 Getting Started With Pacman Commands in Arch-based Linux Distributions.md b/sources/tech/20200419 Getting Started With Pacman Commands in Arch-based Linux Distributions.md deleted file mode 100644 index 1e9567a2f7..0000000000 --- a/sources/tech/20200419 Getting Started With Pacman Commands in Arch-based Linux Distributions.md +++ /dev/null @@ -1,250 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (Chao-zhi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Getting Started With Pacman Commands in Arch-based Linux Distributions) -[#]: via: (https://itsfoss.com/pacman-command/) -[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/) - -Getting Started With Pacman Commands in Arch-based Linux Distributions -====== - -_**Brief: This beginner’s guide shows you what you can do with pacmancommands in Linux, how to use them to find new packages, install and upgrade new packages, and clean your system.**_ - -The [pacman][1] package manager is one of the main difference between [Arch Linux][2] and other major distributions like Red Hat and Ubuntu/Debian. It combines a simple binary package format with an easy-to-use [build system][3]. The aim of pacman is to easily manage packages, either from the [official repositories][4] or the user’s own builds. - -If you ever used Ubuntu or Debian-based distributions, you might have used the apt-get or apt commands. Pacman is the equivalent in Arch Linux. If you [just installed Arch Linux][5], one of the first few [things to do after installing Arch Linux][6] is to learn to use pacman commands. - -In this beginner’s guide, I’ll explain some of the essential usage of the pacmand command that you should know for managing your Arch-based system. - -### Essential pacman commands Arch Linux users should know - -![][7] - -Like other package managers, pacman can synchronize package lists with the software repositories to allow the user to download and install packages with a simple command by solving all required dependencies. - -#### Install packages with pacman - -You can install a single package or multiple packages using pacman command in this fashion: - -``` -pacman -S _package_name1_ _package_name2_ ... -``` - -![Installing a package][8] - -The -S stands for synchronization. It means that pacman first synchronizes - -The pacman database categorises the installed packages in two groups according to the reason why they were installed: - - * **explicitly-installed**: the packages that were installed by a generic pacman -S or -U command - * **dependencies**: the packages that were implicitly installed because [required][9] by another package that was explicitly installed. - - - -#### Remove an installed package - -To remove a single package, leaving all of its dependencies installed: - -``` -pacman -R package_name_ -``` - -![Removing a package][10] - -To remove a package and its dependencies which are not required by any other installed package: - -``` -pacman -Rs _package_name_ -``` - -To remove dependencies that are no longer needed. For example, the package which needed the dependencies was removed. - -``` -pacman -Qdtq | pacman -Rs - -``` - -#### Upgrading packages - -Pacman provides an easy way to [update Arch Linux][11]. You can update all installed packages with just one command. This could take a while depending on how up-to-date the system is. - -The following command synchronizes the repository databases _and_ updates the system’s packages, excluding “local” packages that are not in the configured repositories: - -``` -pacman -Syu -``` - - * S stands for sync - * y is for refresh (local - * u is for system update - - - -Basically it is saying that sync to central repository (master package database), refresh the local copy of the master package database and then perform the system update (by updating all packages that have a newer version available). - -![System update][12] - -Attention! - -If you are an Arch Linux user before upgrading, it is advised to visit the [Arch Linux home page][2] to check the latest news for out-of-the-ordinary updates. If manual intervention is needed an appropriate news post will be made. Alternatively you can subscribe to the [RSS feed][13] or the [arch-announce mailing list][14]. - -Be also mindful to look over the appropriate [forum][15] before upgrading fundamental software (such as the kernel, xorg, systemd, or glibc), for any reported problems. - -**Partial upgrades are unsupported** at a rolling release distribution such as Arch and Manjaro. That means when new library versions are pushed to the repositories, all the packages in the repositories need to be rebuilt against the libraries. For example, if two packages depend on the same library, upgrading only one package, might break the other package which depends on an older version of the library. - -#### Use pacman to search for packages - -Pacman queries the local package database with the -Q flag, the sync database with the -S flag and the files database with the -F flag. - -Pacman can search for packages in the database, both in packages’ names and descriptions: - -``` -pacman -Ss _string1_ _string2_ ... -``` - -![Searching for a package][16] - -To search for already installed packages: - -``` -pacman -Qs _string1_ _string2_ ... -``` - -To search for package file names in remote packages: - -``` -pacman -F _string1_ _string2_ ... -``` - -To view the dependency tree of a package: - -``` -pactree _package_naenter code hereme_ -``` - -#### Cleaning the package cache - -Pacman stores its downloaded packages in /var/cache/pacman/pkg/ and does not remove the old or uninstalled versions automatically. This has some advantages: - - 1. It allows to [downgrade][17] a package without the need to retrieve the previous version through other sources. - 2. A package that has been uninstalled can easily be reinstalled directly from the cache folder. - - - -However, it is necessary to clean up the cache periodically to prevent the folder to grow in size. - -The [paccache(8)][18] script, provided within the [pacman-contrib][19] package, deletes all cached versions of installed and uninstalled packages, except for the most recent 3, by default: - -``` -paccache -r -``` - -![Clear cache][20] - -To remove all the cached packages that are not currently installed, and the unused sync database, execute: - -``` -pacman -Sc -``` - -To remove all files from the cache, use the clean switch twice, this is the most aggressive approach and will leave nothing in the cache folder: - -``` -pacman -Scc -``` - -#### Installing local or third-party packages - -Install a ‘local’ package that is not from a remote repository: - -``` -pacman -U _/path/to/package/package_name-version.pkg.tar.xz_ -``` - -Install a ‘remote’ package, not contained in an official repository: - -``` -pacman -U http://www.example.com/repo/example.pkg.tar.xz -``` - -### Bonus: Troubleshooting common errors with pacman - -Here are some common errors you may encounter while managing packages with pacman. - -#### Failed to commit transaction (conflicting files) - -If you see the following error: - -``` -error: could not prepare transaction -error: failed to commit transaction (conflicting files) -package: /path/to/file exists in filesystem -Errors occurred, no packages were upgraded. -``` - -This is happening because pacman has detected a file conflict and will not overwrite files for you. - -A safe way to solve this is to first check if another package owns the file (pacman -Qo _/path/to/file_). If the file is owned by another package, file a bug report. If the file is not owned by another package, rename the file which ‘exists in filesystem’ and re-issue the update command. If all goes well, the file may then be removed. - -Instead of manually renaming and later removing all the files that belong to the package in question, you may explicitly run _**pacman -S –overwrite glob package**_ to force pacman to overwrite files that match _glob_. - -#### Failed to commit transaction (invalid or corrupted package) - -Look for .part files (partially downloaded packages) in /var/cache/pacman/pkg/ and remove them. It is often caused by usage of a custom XferCommand in pacman.conf. - -#### Failed to init transaction (unable to lock database) - -When pacman is about to alter the package database, for example installing a package, it creates a lock file at /var/lib/pacman/db.lck. This prevents another instance of pacman from trying to alter the package database at the same time. - -If pacman is interrupted while changing the database, this stale lock file can remain. If you are certain that no instances of pacman are running then delete the lock file. - -Check if a process is holding the lock file: - -``` -lsof /var/lib/pacman/db.lck -``` - -If the above command doesn’t return anything, you can remove the lock file: - -``` -rm /var/lib/pacman/db.lck -``` - -If you find the PID of the process holding the lock file with lsof command output, kill it first and then remove the lock file. - -I hope you like my humble effort in explaining the basic pacman commands. Please leave your comments below and don’t forget to subscribe on our social media. Stay safe! - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/pacman-command/ - -作者:[Dimitrios Savvopoulos][a] -选题:[lujun9972][b] -译者:[Chao-zhi](https://github.com/Chao-zhi) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://itsfoss.com/author/dimitrios/ -[b]: https://github.com/lujun9972 -[1]: https://www.archlinux.org/pacman/ -[2]: https://www.archlinux.org/ -[3]: https://wiki.archlinux.org/index.php/Arch_Build_System -[4]: https://wiki.archlinux.org/index.php/Official_repositories -[5]: https://itsfoss.com/install-arch-linux/ -[6]: https://itsfoss.com/things-to-do-after-installing-arch-linux/ -[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/essential-pacman-commands.jpg?ssl=1 -[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-S.png?ssl=1 -[9]: https://wiki.archlinux.org/index.php/Dependency -[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-R.png?ssl=1 -[11]: https://itsfoss.com/update-arch-linux/ -[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-Syu.png?ssl=1 -[13]: https://www.archlinux.org/feeds/news/ -[14]: https://mailman.archlinux.org/mailman/listinfo/arch-announce/ -[15]: https://bbs.archlinux.org/ -[16]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-Ss.png?ssl=1 -[17]: https://wiki.archlinux.org/index.php/Downgrade -[18]: https://jlk.fjfi.cvut.cz/arch/manpages/man/paccache.8 -[19]: https://www.archlinux.org/packages/?name=pacman-contrib -[20]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-paccache-r.png?ssl=1 diff --git a/translated/tech/20200419 Getting Started With Pacman Commands in Arch-based Linux Distributions.md b/translated/tech/20200419 Getting Started With Pacman Commands in Arch-based Linux Distributions.md new file mode 100644 index 0000000000..d33bb59f36 --- /dev/null +++ b/translated/tech/20200419 Getting Started With Pacman Commands in Arch-based Linux Distributions.md @@ -0,0 +1,250 @@ +[#]: collector: (lujun9972) +[#]: translator: (Chao-zhi) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (Getting Started With Pacman Commands in Arch-based Linux Distributions) +[#]: via: (https://itsfoss.com/pacman-command/) +[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/) + +基于 Arch 的 Linux 发行版中 Pacman 命令入门 +====== + +_**简介:这本初学者指南向您展示了在 Linux 中可以使用 pacman 命令做什么,如何使用它们来查找新的软件包,安装和升级新的软件包,以及清理您的系统。**_ + +[pacman][1] 包管理器是 [Arch Linux][2] 和其他主要发行版如 Red Hat 和 Ubuntu/Debian 之间的主要区别之一。它结合了简单的二进制包格式和易于使用的[构建系统 ][3]。pacman 的目标是方便地管理软件包,无论它是来自[官方库 ][4] 还是用户自己的构建软件库。 + +如果您曾经使用过 Ubuntu 或基于 debian 的 发行版,那么您可能使用过 apt-get 或 apt 命令。pacman 在 Arch Linux 中是同样的。如果你[刚刚安装了 Arch Linux][5],在安装 Arch Linux 后,首先要做的[几件事 ][6] 之一就是学习使用 pacman 命令。 + +在这个初学者指南中,我将解释一些基本的 pacman 命令的用法,你应该知道如何用这些命令来管理你的基于 Archlinux 的系统。 + +### Arch Linux 用户应该知道的几个重要的 pacman 命令 + +![][7] + +与其他包管理器一样,pacman 可以将包列表与软件库同步,它能够自动解决所有所需的依赖项,以使得用户可以通过一个简单的命令下载和安装软件。 + +#### 通过 pacman 安装软件 + +你可以用一下形式的代码来安装一个或者多个软件包: + +``` +pacman -S _package_name1_ _package_name2_ ... +``` + +![安装一个包 ][8] + +-S 选项的意思是同步 (synchronization),它的意思是 pacman 在安装之前先与软件库进行同步。 + +pacman 数据库根据安装的原因将安装的包分为两组: + + * **显式安装**:由 pacman -S 或 -U 命令直接安装的包 + * **依赖安装**:由于被其他显式安装的包所[依赖 ][9],而被自动安装的包。 + + + +#### 卸载已安装的软件包 + +卸载一个包,并且删除它的所有依赖。 + +``` +pacman -R package_name_ +``` + +![移除一个包 ][10] + +删除一个包,以及其不被其他包所需要的依赖项: + +``` +pacman -Rs _package_name_ +``` + +删除所有不再需要的依赖项。比如,需要这个依赖的包已经被删除了。 + +``` +pacman -Qdtq | pacman -Rs - +``` + +#### 升级软件包 + +Pacman 提供了一个简单的办法来[升级 Arch Linux][11]。你只需要一条命令就可以升级所有已安装的软件包。这可能需要一段时间,这取决于系统的新旧程度。 + +以下命令可以同步存储库数据库 _并且_ 更新系统的所有软件包,但不包括不在软件库中的“本地安装的”包: + +``` +pacman -Syu +``` + + * S 代表同步 + * y 代表更新本地存储库 + * u 代表系统更新 + + + +也就是说,同步到中央存储库(主程序包数据库),刷新主程序包数据库的本地副本,然后执行系统更新(通过更新所有有更新版本可用的程序包)。 + +![系统更新 ][12] + +注意! + +Arch Linux 用户在系统升级前,建议您访问 [Arch-Linux 主页 ][2] 查看最新消息,以了解异常更新的情况。如果系统更新需要人工干预,主页上将发布相关的新闻。您也可以订阅 [RSS feed][13] 或 [Arch 的声明邮件 ][14]。 + +在升级基础软件(如 kernel、xorg、systemd 或 glibc) 之前,请注意查看相应的 [论坛 ][15],以了解大家报告的各种问题。 + +**在 Arch 和 Manjaro 等滚动发行版中不支持仅部分升级**。这意味着,当新的库版本被推送到存储库时,存储库中的所有包都需要根据库进行升级。例如,如果两个包依赖于同一个库,则仅升级一个包可能会破坏依赖于库的旧版本的另一个包。 + +#### 用 Pacman 查找包 + +Pacman 使用 -Q 选项查询本地包数据库,使用 -S 选项查询同步数据库,使用 -F 选项查询文件数据库。 + +Pacman 可以在数据库中搜索包,包括包的名称和描述: + +``` +pacman -Ss _string1_ _string2_ ... +``` + +![查找一个包 ][16] + +查找已经被安装的包: + +``` +pacman -Qs _string1_ _string2_ ... +``` + +根据文件名在远程数据库中查找它所属的包: + +``` +pacman -F _string1_ _string2_ ... +``` + +查看一个包的依赖树: + +``` +pactree _package_naenter code hereme_ +``` + +#### 清除包缓存 + +Pacman 将其下载的包存储在 /var/cache/Pacman/pkg/ 中,并且不会自动删除旧版本或卸载的版本。这有一些优点: + + 1。它允许[降级 ][17] 一个包,而不需要通过其他来源检索以前的版本。 + 2。已卸载的软件包可以轻松地直接从缓存文件夹重新安装。 + + + +但是,有必要定期清理缓存以防止文件夹增大。 + +[pacman contrib][19] 包中提供的 [paccache(8)][18] 脚本默认情况下会删除已安装和未安装包的所有缓存版本,但最近 3 个版本除外: + +``` +paccache -r +``` + +![清除缓存 ][20] + +要删除当前未安装的所有缓存包和未使用的同步数据库,请执行: + +``` +pacman -Sc +``` + +要从缓存中删除所有文件,请使用 clean 选项两次,这是最激进的方法,不会在缓存文件夹中留下任何内容: + +``` +pacman -Scc +``` + +#### 安装本地或者第三方的包 + +安装不是来自远程存储库的“本地”包: + +``` +pacman -U _/path/to/package/package_name-version.pkg.tar.xz_ +``` + +安装官方存储库中未包含的“远程”软件包: + +``` +pacman -U http://www.example.com/repo/example.pkg.tar.xz +``` + +### 额外内容:用 pacman 排除常见错误 + +下面是使用 pacman 管理包时可能遇到的一些常见错误。 + +#### 提交事务失败(文件冲突) + +如果你看到以下报错: + +``` +error: could not prepare transaction +error: failed to commit transaction (conflicting files) +package: /path/to/file exists in filesystem +Errors occurred, no packages were upgraded. +``` + +这是因为 pacman 检测到文件冲突,不会为您覆盖文件。 + +解决这个问题的一个安全方法是首先检查另一个包是否拥有这个文件 (pacman-Qo\path/to/file)。如果该文件属于另一个包,请提交错误报告。如果文件不属于另一个包,请重命名“存在于文件系统中”的文件,然后重新发出 update 命令。如果一切顺利,文件可能会被删除。 + +您可以显式地运行 **pacman -S –overwrite glob package**,强制 pacman 覆盖与 _glob_ 匹配的文件,而不是手动重命名并在以后删除属于所讨论的包的所有文件。 + +#### 提交事务失败(包无效或损坏) + +在 /var/cache/pacman/pkg/ 中查找 .part 文件(部分下载的包),并将其删除。这通常是由在 pacman.conf 文件中使用自定义 XferCommand 引起的。 + +#### 初始化事务失败(无法锁定数据库) + +当 pacman 要修改包数据库时,例如安装包时,它会在 /var/lib/pacman/db.lck 处创建一个锁文件。这可以防止 pacman 的另一个实例同时尝试更改包数据库。 + +如果 pacman 在更改数据库时被中断,这个过时的锁文件可能仍然保留。如果您确定没有 pacman 实例正在运行,那么请删除锁文件。 + +检查进程是否持有锁定文件: + +``` +lsof /var/lib/pacman/db.lck +``` + +如果上述命令未返回任何内容,则可以删除锁文件: + +``` +rm /var/lib/pacman/db.lck +``` + +如果您发现 lsof 命令输出了使用锁文件的进程的 PID,请先杀死这个进程,然后删除锁文件。 + +我希望你喜欢我对 Pacman 基础命令的解释。请在下面留言,不要忘记订阅我们的社交媒体。注意安全! + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/pacman-command/ + +作者:[Dimitrios Savvopoulos][a] +选题:[lujun9972][b] +译者:[Chao-zhi](https://github.com/Chao-zhi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/dimitrios/ +[b]: https://github.com/lujun9972 +[1]: https://www.archlinux.org/pacman/ +[2]: https://www.archlinux.org/ +[3]: https://wiki.archlinux.org/index.php/Arch_Build_System +[4]: https://wiki.archlinux.org/index.php/Official_repositories +[5]: https://itsfoss.com/install-arch-linux/ +[6]: https://itsfoss.com/things-to-do-after-installing-arch-linux/ +[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/essential-pacman-commands.jpg?ssl=1 +[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-S.png?ssl=1 +[9]: https://wiki.archlinux.org/index.php/Dependency +[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-R.png?ssl=1 +[11]: https://itsfoss.com/update-arch-linux/ +[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-Syu.png?ssl=1 +[13]: https://www.archlinux.org/feeds/news/ +[14]: https://mailman.archlinux.org/mailman/listinfo/arch-announce/ +[15]: https://bbs.archlinux.org/ +[16]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-pacman-Ss.png?ssl=1 +[17]: https://wiki.archlinux.org/index.php/Downgrade +[18]: https://jlk.fjfi.cvut.cz/arch/manpages/man/paccache.8 +[19]: https://www.archlinux.org/packages/?name=pacman-contrib +[20]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/04/sudo-paccache-r.png?ssl=1