How to install the packages mentioned in a file?

Using apt-get, you can easily install any package in debian/ubuntu based system. Suppose you have a list of files mentioned in a file and you want to install all those packages, you can easily do so with the help of the following shell script

#! /bin/sh
if [ $# -ne 1 ]
then echo "Usage: filename";
exit 1;

if [ ! -f $1 ]
then echo "File $1 doesn't exist";
exit 1;

while read line
  pkg=`echo $line| awk '{print $1}'`
  echo $pkg
  yes|sudo apt-get install $pkg
done < $1

Suppose the packages to be installed is mentioned in the file libraries-php.txt

$ cat libraries-php.txt
php5-dbg - Debug symbols for PHP5
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-gmp - GMP module for php5
php5-ldap - LDAP module for php5
php5-mysql - MySQL module for php5
php5-odbc - ODBC module for php5
php5-pgsql - PostgreSQL module for php5
php5-pspell - pspell module for php5
php5-recode - recode module for php5

Now let’s execute the above script

./ libraries-php.txt

You will be asked password during the first package installation. Thus with the above script, you can easily specify the packages you want to install and specify the file name as argument

$ ./ filename

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s