15

I have a fresh install of Lubuntu and would like to install packages from a given list, without having to type sudo apt-get install package_name. Is it possible?

I'm not talking about the post-install scripts, that is something entirely different.

syntagma
  • 569

3 Answers3

38

If you have file (say pkglist) which contains list of packages to be installed like:

pkg1
pkg2
pkg3

or

pkg1 pkg2 pkg3

Then you can install those packages with apt by any of the following commands:

  1. sudo apt-get install $(cat pkglist)

  2. xargs sudo apt-get install < pkglist

  3. for i in $(cat pkglist); do sudo apt-get install $i; done

3rd one is recommended as it does work even if some pkgs are not found in the repository whereas 1st two would fail to install the available packages as addressed in this comment

For more information on apt-get install visit man apt-get install section.

Pandya
  • 35,771
  • 44
  • 128
  • 188
6

Yep, just list all packages in a line separated by a space. e.g.

sudo apt-get install package_name1 package_name2 package_name3 package_name4
Sparhawk
  • 6,929
2

Put all the package names into a file (one package name for each line). And then run the below command to install the given packages automatically.

while read -r line; do sudo apt-get -y install "$line"; done < /path/to/the/packages/file

Example:

$ cat file
vlc
firefox
$ while read -r line; do sudo apt-get install "$line"; done < file
[sudo] password for avinash: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
vlc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 499 not upgraded.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  ttf-lyx
The following packages will be upgraded:
  firefox
1 upgraded, 0 newly installed, 0 to remove and 498 not upgraded.
Need to get 35.8 MB of archives.
After this operation, 24.3 MB of additional disk space will be used.
Get:1 http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-updates/main firefox amd64 33.0+build2-0ubuntu0.14.04.1 [35.8 MB]
0% [1 firefox 67.0 kB/35.8 MB 0%]                           10.4 kB/s 57min 16s^
Avinash Raj
  • 78,556
  • 1
    Wouldn't this be a lot slower than just putting the packages on one line, as it has to read package lists and build dependency trees, etc. for each package, rather than doing it once? – Sparhawk Oct 27 '14 at 00:22