How to List Installed Packages (`pacman -Q`) on Arch Linux
pacman -Q
) on Arch LinuxCategories:
5 minute read
Arch Linux is a powerful and minimalist distribution that gives users fine-grained control over their system. One of the key tools for managing software on Arch Linux is pacman
, the default package manager. Among its many capabilities, pacman
allows users to list installed packages on the system, which can be extremely useful for troubleshooting, documentation, system audits, or migration to another system.
In this article, we’ll explore in depth how to list installed packages using pacman -Q
and related options. We’ll also look at how to filter and manipulate the output to get exactly the information you need.
Why List Installed Packages?
Before diving into the commands, let’s briefly cover why you might want to list installed packages:
- System auditing: See what’s installed, especially useful in enterprise or production environments.
- Backup and migration: When moving to a new system, you may want to reinstall the same packages.
- Troubleshooting: Identify potentially problematic or outdated packages.
- Documentation: Maintain a record of system state for compliance or personal reference.
- Optimization: Identify and remove unused packages to keep the system lean.
The Basics: pacman -Q
The simplest way to list all installed packages is by running:
pacman -Q
This command will return a list where each line contains the name and version of an installed package:
bash 5.2.015-1
coreutils 9.4-1
gcc 13.2.1-1
Here’s a breakdown of the syntax:
-Q
: This tellspacman
to query the local package database (i.e., installed packages).- No additional flags mean that all installed packages will be listed.
Output Customization with Sorting
You might want to sort the output alphabetically for easier reading:
pacman -Q | sort
Or, if you want to see a count of installed packages:
pacman -Q | wc -l
Filtering Output
1. Search for a Specific Package
You can filter for a specific package using grep
:
pacman -Q | grep firefox
This will list all installed packages that have “firefox” in the name.
2. List Only Explicitly Installed Packages
When you install a package directly using pacman -S
, it’s considered explicitly installed. Packages installed as dependencies are marked as such and aren’t explicitly installed.
To see only explicitly installed packages:
pacman -Qe
Useful for generating a list of packages you specifically chose to install.
You can save this to a file for backup:
pacman -Qe > my-packages.txt
3. List Only Dependencies
If you’re auditing your system or want to clean unused dependencies, this will help:
pacman -Qd
This lists packages that were installed as dependencies (and may or may not still be required).
To see dependencies that are not required anymore:
pacman -Qdt
This command is extremely useful when cleaning orphaned packages.
Querying Specific Packages
You can also query a specific package and get detailed information about it:
pacman -Qi bash
This gives detailed info like install date, description, dependencies, etc.
Sample output:
Name : bash
Version : 5.2.015-1
Description : The GNU Bourne Again shell
Architecture : x86_64
Install Date : Tue 26 Mar 2024 02:18:12 PM UTC
...
To list files installed by a package:
pacman -Ql bash
To find out which package a particular file belongs to:
pacman -Qo /bin/bash
List Packages from a Specific Repository
Sometimes you want to see which installed packages came from a specific repository, such as core
, extra
, or community
.
This command filters installed packages by repo:
pacman -Sl core | grep '\[installed\]'
Explanation:
pacman -Sl core
: Lists all packages in thecore
repo.grep '\[installed\]'
: Filters to only those already installed.
List Packages by Install Date
Arch does not directly track install date of all packages, but using expac
, you can list packages by install time:
expac -H M "%09i\t%n" | sort
Explanation:
%i
: Install date (epoch)%n
: Package name-H M
: Output format in human-readable format with month abbreviation.
You can also sort by install date in descending order:
expac -H M "%l\t%n" | sort -r
If expac
is not installed, you can get it via:
sudo pacman -S expac
Exporting and Reinstalling Installed Packages
To export a list of all explicitly installed packages:
pacman -Qqe > pkglist.txt
To reinstall them on another Arch system:
sudo pacman -S --needed - < pkglist.txt
This is especially useful when setting up a new system or after a reinstall.
List Installed AUR Packages
pacman
does not handle AUR packages directly, but you can use an AUR helper like yay
or query the package info to identify AUR packages.
To list packages not found in official repos (likely AUR):
comm -23 <(pacman -Qq | sort) <(pacman -Qqm | sort)
Or just list packages from the AUR using:
pacman -Qm
Explanation:
-Qm
: Lists foreign packages (not found in sync DB), which usually means AUR.
Scripting and Automation
To parse package names and versions into a script-friendly format:
pacman -Q | awk '{print $1 "=" $2}'
This could be useful for syncing versions across machines.
For JSON output (not supported directly by pacman), you can combine with other tools like jq
or write your own parser.
Helpful Aliases and Tips
You might want to create some bash aliases to save time:
alias listall='pacman -Q'
alias listexplicit='pacman -Qe'
alias listorphans='pacman -Qdt'
alias listaur='pacman -Qm'
Add these to your ~/.bashrc
or ~/.zshrc
for convenience.
Troubleshooting
pacman
reports an error or missing database
Ensure your package database is up to date:
sudo pacman -Sy
Avoid using -Sy
without -u
in scripts, but it’s okay before querying data.
expac
not found
Make sure it’s installed:
sudo pacman -S expac
Conclusion
Understanding how to list installed packages with pacman -Q
and related commands is an essential skill for any Arch Linux user. Whether you’re managing a single system or maintaining a fleet of machines, this knowledge gives you better control, transparency, and reproducibility over your system configuration.
From listing everything installed to filtering by repo, package origin, or install date, pacman
offers a powerful suite of options that—when combined with simple Unix tools like grep
, sort
, and awk
—provide almost endless flexibility.
Arch Linux may be known for its DIY approach, but once you get familiar with tools like pacman -Q
, you’ll find that managing packages becomes both efficient and enjoyable.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.