Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the pacman command of Arch Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to use Arch Linux's pacman command, which is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The pacman command can find new installation packages, install and upgrade new installation packages, and clean up the system in the Linux system.

Several important pacman commands that Arch Linux users should know

Like other package managers, pacman synchronizes the package list with the software library, and it automatically resolves all necessary dependencies so that users can download and install the software with a simple command.

Install the software through pacman

You can install one or more software packages with the following forms of code:

Pacman-S package name 1 package name 2...

Install a package

The-S option means to synchronize synchronization, which means that pacman is synchronized with the software library before installation.

The pacman database divides the installed packages into two groups according to the reasons for the installation:

Explicit installation: packages installed directly by the pacman-S or-U command

Dependent installation: a package that is automatically installed because it is dependent on other explicitly installed packages.

Uninstall installed packages

Uninstall a package and remove all its dependencies.

Pacman-R package name

Remove a package

Delete a package and its dependencies that are not required by other packages:

Pacman-Rs package name

If the package that needs this dependency has been deleted, this command removes all dependencies that are no longer needed:

Pacman-Qdtq | pacman-Rs-

Upgrade package

Pacman provides an easy way to upgrade Arch Linux. You only need one command to upgrade all installed packages. This may take a while, depending on how old and new the system is.

The following command synchronizes the repository database and updates all software packages for the system, excluding "locally installed" packages that are not in the repository:

Pacman-Syu

S stands for synchronization

Y stands for updating the local repository

U stands for system update

That is, synchronize to the central software library (the main package database), refresh the local copy of the main package database, and then perform a system update (by updating all packages available with updated versions).

System update

Be careful!

For Arch Linux users, before upgrading the system, it is recommended that you visit the Arch-Linux home page to check the latest news to learn about abnormal updates. If a system update requires human intervention, relevant news will be posted on the home page. You can also subscribe to the announcement email from the RSS feed or Arch.

Before upgrading the basic software (such as kernel, xorg, systemd, or glibc), please check the appropriate forums to understand the various issues reported.

Partial upgrades are not supported in rolling distributions such as Arch and Manjaro. This means that when a new library version is pushed to the library, all packages in the library need to be upgraded according to the library version. For example, if two packages depend on the same library, upgrading only one package may break the other package that depends on the older version of the library.

Use Pacman to find packages

Pacman uses the-Q option to query the local package database, the-S option to query the synchronization database, and the-F option to query the file database.

Pacman can search the database for packages, including the package name and description:

Pacman-Ss string 1 string 2...

Find a package

Find the packages that have been installed:

Pacman-Qs string 1 string 2...

Look for the package to which it belongs in the remote soft package based on the file name:

Pacman-F string 1 string 2...

View the dependency tree of a package:

Pactree package name

Clear the package cache

Pacman stores its downloaded packages in / var/cache/Pacman/pkg/ and does not automatically delete old or uninstalled versions. This has some advantages:

It allows you to downgrade a package without having to retrieve previous versions from other sources.

Uninstalled packages can be easily reinstalled directly from the cache folder.

However, it is necessary to clean the cache periodically to prevent the folder from growing.

The paccache (8) script provided in the pacman contrib package removes all cached versions of installed and uninstalled packages by default, except for the most recent 3 versions:

Paccache-r

Clear cach

To delete all currently uninstalled cache packages and unused synchronization databases, execute:

Pacman-Sc

To delete all files from the cache, use the clear option twice, which is the most radical method and does not leave anything in the cache folder:

Pacman-Scc

Install local or third-party packages

Install a "local" package that is not from a remote repository:

Pacman-U Local package path .pkg.tar.xz

Install "remote" packages that are not included in the official repository:

Pacman-U http://www.example.com/repo/example.pkg.tar.xz

Extra: use pacman to troubleshoot common errors

Here are some common errors that you may encounter when using pacman to manage packages.

Failed to commit transaction (file conflict)

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 because pacman detects file conflicts and will not overwrite files for you.

A safe way to solve this problem is to first check whether another package owns this file (the pacman-Qo file path). If the file belongs to another package, please submit an error report. If the file does not belong to another package, rename the file that exists in the file system, and then reissue the update command. If all goes well, the file may be deleted.

You can explicitly run the file mode to be overwritten by pacman-S-overwrite * *, forcing pacman` to overwrite files that match the given pattern, rather than manually renaming and deleting all files belonging to the package later.

Failed to commit transaction (invalid or corrupted package)

Look for the .part file (the partially downloaded package) in / var/cache/pacman/pkg/ and delete it. This is usually caused by the use of custom XferCommand in pacman.conf files.

Failed to initialize transaction (unable to lock database)

When pacman wants to modify the package database, such as installing the package, it creates a lock file at / var/lib/pacman/db.lck. This prevents another instance of pacman from trying to change the package database at the same time.

If pacman is interrupted while changing the database, this obsolete lock file may still be retained. If you are sure that no pacman instance is running, delete the lock file.

Check whether the process holds a locked file:

Lsof / var/lib/pacman/db.lck

If the above command returns nothing, you can delete the lock file:

Rm / var/lib/pacman/db.lck

If you find that the lsof command outputs the PID of a process that uses the lock file, kill the process first, and then delete the lock file.

The above is how to use Arch Linux's pacman command. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report