I\'m working on a Ubuntu system and currently this is what I\'m doing:
if ! which command > /dev/null; then
echo -e \"Command not found! Install? (y/n)
This command is the most memorable:
dpkg --get-selections <package-name>
If it's installed it prints:
<package-name> install
Otherwise it prints
No packages found matching <package-name>.
This was tested on Ubuntu 12.04.1 (Precise Pangolin).
It seems that nowadays apt-get
has an option --no-upgrade
that just does what the OP wants:
--no-upgrade
Do not upgrade packages. When used in conjunction with install, no-upgrade will prevent packages listed from being upgraded if they are already installed.
Manpage from https://linux.die.net/man/8/apt-get
Therefore you can use
apt-get install --no-upgrade package
and package
will be installed only if it's not.
Many things has been told but for me simplest way is:
dpkg -l | grep packagename
This will do it. apt-get install
is idempotent.
sudo apt-get install command