Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out, whether a specific package is already installed in Arch Linux

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?

like image 934
Random Citizen Avatar asked Oct 09 '14 09:10

Random Citizen


People also ask

How do you check if a specific package is installed?

The dpkg-query command can be used to show if a specific package is installed in your system. To do it, run dpkg-query followed by the -l flag and the name of the package you want information about.


2 Answers

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 
like image 159
Fredszaq Avatar answered Oct 13 '22 00:10

Fredszaq


You can use the arch package management tool pacman.
As you can see in the Arch-Wiki, the -Qs option can be used to search within the installed packages.

If the package exists, pacman -Qs will exit with the exit-code 0, otherwise with the exit-code 1

You script might look like:

package=firefox if pacman -Qs $package > /dev/null ; then   echo "The package $package is installed" else   echo "The package $package is not installed" fi 

The > /dev/null pipe is used to suppress the printed output.

like image 28
Random Citizen Avatar answered Oct 13 '22 00:10

Random Citizen