• Rutvik Hajare

Getting Started With Pacman Commands in Arch-based Linux Distributions

Updated: May 4, 2020

The pacman package manager is one of the main difference between Arch Linux and other major distributions like Red Hat and Ubuntu/Debian. It combines a simple binary package format with an easy-to-use build system. The main use of pacman is to easily manage packages, either from the official repositories or the user’s own builds.


Have 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, one of the first few things to do after installing Arch Linux is to learn to use pacman commands.


In this article, I’m going to 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


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_ ...

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 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_

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. 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).

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_ ...

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 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) script, provided within the pacman-contrib package, deletes all cached versions of installed and uninstalled packages, except for the most recent 3, by default:

paccache -r

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

Thank you !

11 views0 comments

Overview

Doceeo gives the ideas, tricks, tips and tutorials about the technology.
get info about the OS.
@2020 all right are reserved by Doceeo

Contact

  • Facebook
  • Twitter
  • Pinterest

Follow on Reddit

reddit-alien-red-st.jpg