我怎样才能知道Arch Linux中是否已经安装了特定的软件包

Ran*_*zen 18 linux bash archlinux

我想编写一个bash脚本,允许我检查是否已经在arch linux中安装了某个软件包.

我怎样才能做到这一点?

Fre*_*zaq 32

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>
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)