Issue
I want to write a bash script allowing me to check, whether a certain package is already installed in arch linux.
How can I do that?
Solution
You should use Pacman, the package manager of Arch Linux.
You want to use the -Q
operation to query the installed local package database and the -i
option to get information on the package.
This gives you
pacman -Qi <packageName>
You can then use the exit code to determine if the packages existes on the system or not (0 the package exists, 1 it doesn't)
The usage of -i
rather than -s
ensures you will check for exactly that package and not for the presence of a a package containing the package name in its name.
For example if I search for chromium
(the web browser) on a system where only chromium-bsu
(the game) is installed,
# This exits with 1 because chromium is not installed
pacman -Qi chromium
# This exits with 0 because chromium-bsu is installed
pacman -Qs chromium
As Random Citizen pointed out, you certainly want to redirect any output to /dev/null
if you are writing a script and don't want Pacman to pollute your output:
pacman -Qi <packageName> > /dev/null
Answered By - Fredszaq Answer Checked By - Dawn Plyler (WPSolving Volunteer)