Ubuntu – Install a list of packages only if they aren’t already installed

11.10aptdpkgpackage-management

I'm trying to automate my setup as much as possible.

To do this I have lists of packages that I want to install, for example: banshee wireshark audacity thunderbird thunderbird-lightning calibre deluge unison-gtk usb-creator-kde ding digikam chromium-browser bleachbit soundconverter kdenlive firefox-kde-support vlc kwrite openjdk-6-jre icedtea6-plugin virtualbox virtualbox-guest-additions-iso.

I want to write a small bash script to call apt-get to install these packages only if they're not already installed.

Currently I have this but it doesn't work:

dpkg -s "$1" > /dev/null 2>&1 || apt-get -y install "$1", (where $1 is the list)

Best Answer

apt-get will fairly silently skip over any package that is installed already so I'm not sure why it needs to get special treatment? ie:

root@bun:~# apt-get -y install  vlc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
vlc is already the newest version.

Is there a particular reason this won't work for you as-is?

Related Question