How to List Installed Packages With Pacman
Pacman is one of the major distinguishing features of Arch Linux. It keeps the system up-to-date by synchronizing package lists with the master server. This server/client model allows the user to download and install packages with a simple command.
Pacman can handle dependencies for you, meaning you only need to specify the program and Pacman installs it along with every other program it depends on. This makes it easy to update existing packages as soon as updates are available.
Installing Packages with Pacman
To install packages on Arch Linux, use the Pacman command with the -S
option and mention the package name. The -S
option tells Pacman to synchronize and continue. For example, to install a package named package_name
, you would use the following command:
pacman -S package_name
Listing Installed Packages
You can use the Pacman command with the -Q
option to list all installed packages on your system. For example:
pacman -Q
For users interested in identifying explicitly installed packages, which are those installed by the user and not as dependencies, the command is:
pacman -Qe
To differentiate between native packages (those available in the official repositories) and foreign packages (manually installed or not available in the repositories), use:
pacman -Qn # for native packages pacman -Qm # for foreign packages
This command generates a list of all installed packages in two columns. If you want to show only the first column, which contains the package names, you can use the awk
command to filter the output:
pacman -Q | awk '{print $1}'
To export the list to a file, you can redirect the output to a text file:
pacman -Q | awk '{print $1}' > package_list.txt
Pacman also allows for more refined searches using regular expressions:
pacman -Qs regex
For users who want to filter out installed packages from search results, a combination of pacman
and sed
can be used:
pacman -Ss search_term | sed '/\S.*\[installed\]/,/^\s/d'
Advanced users can list explicitly installed native packages that are not dependencies using:
pacman -Qent
For custom output formats, expac
can be utilized alongside pacman
:
expac -s "%-30n %v" regex
Searching for Packages
Pacman provides several options for searching for packages. The -Ss
option allows you to search the package database for a specific package. For example, to search for a package named package_name
, you would use the following command:
pacman -Ss package_name
If you want to search for a package in the repositories but only want to see uninstalled packages, you can use a sed
pattern to filter packages which are marked with [installed]
:
pacman --color=always -Ss search_term | sed '/\S.*\[installed\]/,/^\s/d'
Troubleshooting Pacman
If Pacman is interrupted while changing the database, a stale lock file can remain at /var/lib/pacman/db.lck
. This prevents another instance of Pacman from trying to alter the package database at the same time. If you are certain that no instances of Pacman are running, you can remove the lock file:
rm /var/lib/pacman/db.lck
Conclusion
Pacman is a powerful tool for managing packages on Manjaro or Arch Linux-based. With its easy-to-use command-line interface, you can install, update, remove, and list packages with ease. By understanding how to use Pacman effectively, you can ensure that your Arch Linux system is always up-to-date and equipped with the software it needs. Whether you’re a seasoned Linux user or new to the Arch Linux environment, mastering Pacman is a crucial step in your journey.