How to List Installed Packages With Pacman
Managing packages efficiently is crucial for anyone working with Arch Linux or its derivatives. Pacman, the default package manager for Arch Linux, offers powerful capabilities for handling software installations, updates, and removals. One of its most useful features is the ability to list installed packages, which helps in system maintenance, troubleshooting, and backup processes. This comprehensive guide explores various methods to list installed packages using Pacman, providing you with the tools to better understand and manage your Linux system.
Understanding Pacman in Arch Linux
Pacman stands as the cornerstone of package management in Arch Linux. Unlike other package managers such as APT (used in Debian/Ubuntu) or DNF/YUM (used in Fedora/RHEL), Pacman uses a simple yet powerful approach to package management.
Pacman handles packages in a single compressed file format (.pkg.tar.xz), which contains all the files to be installed along with metadata. This approach offers several advantages:
- Simplicity: Pacman’s command structure is straightforward and easy to remember
- Speed: Package operations are notably faster due to efficient compression
- Dependency resolution: Automatic handling of package dependencies
- Synchronization: Easy system-wide updates with a single command
The configuration for Pacman resides in /etc/pacman.conf
, where you can modify settings like repository information, architecture preferences, and more. The mirror list, which determines which servers Pacman uses to download packages, is located at /etc/pacman.d/mirrorlist
.
Before diving into listing packages, it’s worth noting that Pacman’s basic syntax follows a simple pattern:
pacman -[operation] [options] [targets]
Where operations include S (sync), Q (query), and R (remove), each accepting various additional options to modify their behavior.
Basic Package Listing Commands
The most fundamental command for listing installed packages with Pacman is using the query (-Q) operation. When executed without additional parameters, this command displays all packages installed on your system:
pacman -Q
This command produces output in two columns: the first showing package names and the second displaying their installed versions. For example:
acl 2.3.1-2
acpid 2.0.34-1
archlinux-keyring 20220927-1
attr 2.5.1-2
bash 5.1.016-1
If you want to focus solely on package names without version information, pipe the output through awk:
pacman -Q | awk '{print $1}'
This produces a cleaner list containing only package names:
acl
acpid
archlinux-keyring
attr
bash
To save this list to a file for future reference or system replication, redirect the output:
pacman -Q > packages.txt
For package names only:
pacman -Q | awk '{print $1}' > package_list.txt
These basic commands form the foundation for more complex package listing operations, which we’ll explore in subsequent sections.
Listing Explicitly Installed Packages
Not all packages on your system were directly installed by you. Many are dependencies pulled in automatically to satisfy requirements of other packages. Understanding the difference between explicitly installed packages and dependencies is crucial for effective system management.
To list packages that were explicitly installed (as opposed to being pulled in as dependencies), use:
pacman -Qe
This command displays packages explicitly requested for installation. The output format remains the same as the basic -Q
command, but the list will be shorter, excluding dependencies.
For even more control, you can combine multiple options. For instance, to list explicitly installed packages that aren’t dependencies of other packages:
pacman -Qet
This command is particularly useful for identifying the core applications you’ve chosen to install, separate from their supporting packages. It helps answer the question, “What software did I actually choose to install on this system?”
Understanding installation reasons becomes especially important when cleaning up your system. By knowing which packages were explicitly installed, you can make more informed decisions about what to keep or remove.
Why This Matters: When migrating to a new system or performing a fresh installation, having a list of explicitly installed packages allows you to quickly replicate your software environment without including unnecessary dependencies.
Filtering Package Lists by Source
Arch Linux packages come from different sources, and sometimes you need to distinguish between them. Pacman provides options to filter packages based on their origin.
Listing Native Packages
Native packages come from the official Arch repositories. To list these packages:
pacman -Qn
This command shows all packages installed from the official repositories, excluding any foreign packages (those installed from outside the standard repositories).
Listing Foreign Packages
Foreign packages include those installed from the Arch User Repository (AUR), manually installed packages, or those from third-party repositories. To list these:
pacman -Qm
This command is particularly useful for identifying packages that might not receive updates through the standard system update process or that might require special attention during major system upgrades.
You can combine these source filters with other options. For example, to list explicitly installed foreign packages:
pacman -Qme
Understanding the source of your installed packages helps maintain system integrity and troubleshoot potential package conflicts. Foreign packages, especially those from the AUR, may require manual intervention during system updates or when resolving dependencies.
Working with Package Groups
Package groups in Arch Linux represent collections of related packages that serve a common purpose. Working with groups can simplify the management of multiple related packages.
Finding Available Package Groups
To see all available package groups in the repositories:
pacman -Sg
This command lists all defined package groups without showing their contents.
Listing Packages Within Specific Groups
To view the packages contained within a specific group:
pacman -Sg group_name
Replace group_name
with the actual group you’re interested in, such as base
, base-devel
, or xorg
.
Listing Installed Packages from a Group
To check which packages from a specific group are installed on your system:
pacman -Qg group_name
This command is useful for verifying if you have all the recommended packages from a functional group installed, or for identifying group members that could be removed if no longer needed.
Common package groups in Arch Linux include:
base
: Essential packages for a basic Arch Linux installationbase-devel
: Development tools and librariesxorg
: X.Org X server and related packagesgnome
: GNOME desktop environment packages
Understanding package groups helps maintain system consistency and ensures you have all necessary components for specific functionality.
Advanced Filtering and Customization
Pacman’s basic listing capabilities can be extended with additional filters and by combining its output with other command-line tools.
Using Regular Expressions
To search for packages with names or descriptions matching specific patterns:
pacman -Qs pattern
For more precise filtering, you can use regular expressions. For example, to find all packages whose names start with “vim-“:
pacman -Ss '^vim-'
Combining Pacman with Other Utilities
The real power of Pacman comes when combining it with other command-line utilities. Here are some useful combinations:
List packages excluding those in base and base-devel groups:
comm -23 <(pacman -Qqett | sort | uniq) <(pacman -Qqg base -g base-devel | sort | uniq)
This command uses comm
to compare two sorted lists, showing only lines unique to the first list (packages not in the base or base-devel groups).
Count installed packages:
pacman -Q | wc -l
Sort packages by installation date:
expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort
This requires the expac
package, which provides additional functionality for working with Pacman databases.
Find packages not required by any other package:
pacman -Qtt
These advanced filtering techniques allow for precise package management and system analysis, enabling you to better understand and control your Arch Linux installation.
Listing Packages with Detailed Information
Sometimes you need more than just package names and versions. Pacman provides options to display detailed information about installed packages.
To get comprehensive information about a specific package:
pacman -Qi package_name
This command displays detailed metadata including:
- Description
- Architecture
- Repository source
- Installation size
- Installation date
- Dependencies
- Optional dependencies
- Conflicts
- Replaces information
For even more detailed information, including a list of backup files and their modification states:
pacman -Qii package_name
To view the files installed by a package:
pacman -Ql package_name
This command lists all files owned by the specified package, showing their paths in the filesystem. This is particularly useful when troubleshooting missing files or conflicts.
To verify the presence of all files installed by a package (checking for potential corruption or unauthorized modifications):
pacman -Qk package_name
For a more thorough check:
pacman -Qkk package_name
These detailed queries help when diagnosing issues, planning upgrades, or simply gaining a deeper understanding of your system’s package configuration.
Analyzing Package Sizes
Storage management is important, especially on systems with limited disk space. Pacman can help identify large packages that might be candidates for removal if no longer needed.
While Pacman itself doesn’t have a direct option to sort packages by size, you can use complementary tools like expac
:
expac -H M '%m\t%n' | sort -hr
This command lists packages sorted by their installed size, with the largest packages at the top. The size is displayed in megabytes for easy readability.
To view the size of a specific package:
pacman -Qi package_name | grep "Installed Size"
Finding and removing unnecessarily large packages can free up significant disk space. Some types of packages that often consume substantial space include:
- Games with extensive assets
- Office suites
- Development environments with comprehensive libraries
- Graphics and video editing software
- Large language models and machine learning frameworks
Regular analysis of package sizes, especially after using a system for an extended period, can help maintain optimal disk usage and system performance.
Exporting and Managing Package Lists
Creating and maintaining package lists is an essential practice for system backup, replication, and disaster recovery.
Creating Backup Package Lists
To create a simple list of all installed packages:
pacman -Q > full_package_list.txt
For a more useful backup aimed at system replication, focus on explicitly installed packages:
pacman -Qe > explicit_packages.txt
To create a list formatted for reinstallation (package names only, without versions):
pacman -Qqe > reinstall_packages.txt
Restoring from Package Lists
To reinstall packages from a saved list:
sudo pacman -S - < reinstall_packages.txt
This command instructs Pacman to install all packages listed in the file.
Automating Package List Backups
Consider setting up a cron job or systemd timer to periodically backup your package lists:
# Example cron entry (weekly backup)
0 0 * * 0 pacman -Qqe > /path/to/backup/explicit_packages_$(date +\%Y\%m\%d).txt
Best practices for package list management include:
- Maintaining separate lists for native and foreign packages
- Documenting custom package configurations alongside package lists
- Dating backup files for version control
- Storing backup files off-system (cloud storage, external drives)
These practices ensure you can quickly recover your system configuration after hardware failures, during system migrations, or when setting up new installations.
Pacman in Daily System Maintenance
Integrated into regular system maintenance routines, Pacman’s package listing capabilities become powerful tools for system optimization.
Identifying Orphaned Packages
Orphaned packages are those installed as dependencies but no longer required by any currently installed package. To list these:
pacman -Qdt
To remove all orphaned packages in one command:
sudo pacman -Rns $(pacman -Qdtq)
Tracking System Changes
Keeping historical package lists helps track system evolution over time:
# Create a dated package list
pacman -Q > packages_$(date +%Y%m%d).txt
Later, you can compare lists to see what has changed:
diff packages_20230101.txt packages_20230601.txt
Troubleshooting Package Issues
When facing package-related problems, listing specific package information can be invaluable:
# Check which package owns a file
pacman -Qo /path/to/file
# Check if any installed packages have missing files
pacman -Qk
# Verify a specific package's integrity
pacman -Qkk package_name
Incorporating these commands into maintenance scripts or regularly scheduled checks helps maintain system integrity and prevent potential issues before they become serious problems.
Alternative Tools and Front-ends
While Pacman is powerful on its own, several auxiliary tools extend its functionality or provide more user-friendly interfaces.
Command-line Helpers
- expac: Provides flexible formatting and querying of Pacman databases
- pkgfile: Allows searching for packages by files they contain
- pacutils: A collection of helper tools for Pacman
To install these:
sudo pacman -S expac pkgfile pacutils
Remember to initialize the pkgfile database after installation:
sudo pkgfile --update
GUI Front-ends
For those who prefer graphical interfaces:
- Pamac: The default package manager in Manjaro Linux, offering a user-friendly interface for Pacman
- Octopi: A Qt-based package manager for Arch Linux
- GNOME Software: Can be configured to work with Pacman
These front-ends simplify package management tasks while leveraging Pacman’s core functionality in the background.
AUR Helpers
To manage packages from the Arch User Repository:
- yay: A feature-rich AUR helper with excellent search capabilities
- paru: A Rust-based AUR helper focused on speed and updates to the original yaourt
- aurutils: A collection of utilities for the AUR
While these tools offer convenience, understanding the underlying Pacman commands remains important for troubleshooting and advanced system maintenance.