bhg0ua
Last Updated: February 25, 2016
·
395
· joseluisq

How to check if some package is installed on linux system via shell

#!/bin/sh

# This test uses the `type` command to check if package is installed.
# Tested on Fedora Linux x64

# Miscellaneous
B=`tput bold`
N=`tput sgr0`

# Package name
PACKAGENAME="git"

# Searching for package on system
FILEPATH="`type -P ${PACKAGENAME}`"

# Checking for package
if [ -z $FILEPATH ];
then
echo "The ${B}${PACKAGENAME}${N} package is not installed on your system."
else
echo "The ${B}${PACKAGENAME}${N} package is already installed at ${B}${FILEPATH}${N}"
fi