Checking whether program is installed

I currently use this construction to check whether a certain program is installed:

if [ ! -e `which sqlite3` ]; then
        cd /usr/ports/databases/sqlite3 && make install clean
else 
        echo "sqlite already installed"
fi

Is this method recommended? Is this an effective method, ie sufficiently robust for other examples, such as gcc, php, perl etc? Are there any caveats to this? The snippet is run as part of a script as root.

I don't think I'd recommend using 'which' in order to determine if software is installed - it is only going to see what is in the user's $PATH. rpm or other package managers can identify based on pattern matching.

Cheers,

Keith

if type sqlite3 >/dev/null 2>&1 ; then
        echo "sqlite already installed"
else 
        cd /usr/ports/databases/sqlite3 && make install clean
fi

Or:

if command -v sqlite3 >/dev/null 2>&1 ; then
        echo "sqlite already installed"
else 
        cd /usr/ports/databases/sqlite3 && make install clean
fi

Thank you for your response. I will try that too.