How to use the command "pacman-query" (with examples)
1. List installed packages and versions
pacman --query
Motivation: This command is useful when you want to get a complete list of all the packages installed on your Arch Linux system along with their versions.
Explanation: The --query
option is used to query the package database and retrieve information about the installed packages. When used without any additional arguments, it lists all installed packages and their versions.
Example Output:
alsa-lib 1.2.4-3
bash 5.1.8-1
coreutils 9.0-3
...
2. List only packages and versions that were explicitly installed
pacman --query --explicit
Motivation: Sometimes, you might want to see only the packages that were explicitly installed by the user rather than packages that were installed as dependencies.
Explanation: The --explicit
option filters the query result to show only the packages that were explicitly installed by the user. This can help identify the packages that you intentionally installed on your system.
Example Output:
alsa-lib 1.2.4-3
bash 5.1.8-1
coreutils 9.0-3
...
3. Find which package owns a file
pacman --query --owns filename
Motivation: When you come across a file on your system and want to know which package it belongs to, you can use this command to find its owner.
Explanation: By specifying the --owns
option followed by the filename, you can find the package that owns the specified file.
Example Output:
/usr/lib/libc.so is owned by glibc 2.34-4
4. Display information about an installed package
pacman --query --info package
Motivation: If you need detailed information about a specific package, such as its description, maintainer, and dependencies, you can use this command.
Explanation: The --info
option followed by the package name displays detailed information about the specified package.
Example Output:
Name : alsa-lib
Version : 1.2.4-3
...
Description : An alternative implementation of Linux sound support (ALSA API)
...
Depends On : glibc
...
Maintainer : Andreas Radke <andyrtr@archlinux.org>
5. List files owned by a package
pacman --query --list package
Motivation: To see a list of files installed by a particular package, this command can help you identify all the files owned by that package.
Explanation: When you specify the package name after the --list
option, it lists all the files installed by the specified package.
Example Output:
/usr/lib/libasound.so.2
/usr/lib/alsa-lib/
/usr/lib/alsa-lib/pcm/
...
6. List orphan packages
pacman --query --unrequired --deps --quiet
Motivation: Orphan packages are those that were installed as dependencies but are no longer needed by any other package on the system. Identifying and removing these packages can help keep your system clean and free from unnecessary bloat.
Explanation: The combination of options --unrequired
, --deps
, and --quiet
helps to list only the orphan packages, excluding packages installed explicitly or required by other packages.
Example Output:
libjpeg-turbo
libxdmcp
libxft
...
7. List installed packages not found in the repositories
pacman --query --foreign
Motivation: Occasionally, you might manually install packages or add third-party repositories, and you would like to see a list of packages that are not available in the official Arch Linux repositories.
Explanation: When you use the --foreign
option, pacman
lists packages that were not installed from the official repositories. These packages are typically installed manually or come from external sources.
Example Output:
spotify 1.1.64.561.g987b60d7
slack-desktop 4.4.2
...
8. List outdated packages
pacman --query --upgrades
Motivation: Regularly updating packages on your system is crucial for maintaining security and stability. This command assists in identifying packages that have available updates.
Explanation: By running the --upgrades
option, pacman
lists packages that have newer versions available in the repositories.
Example Output:
alsa-lib 1.2.4-3 -> 1.2.5.1-1
coreutils 9.0-3 -> 9.1-1
firefox 95.0.2-1 -> 96.0.2-1
...
Conclusion
The pacman --query
command provides a wealth of options to query the package database on Arch Linux. Whether you want to list installed packages, find file owners, or check for updates, these examples demonstrate how to utilize different use cases with pacman
.