How to install a list of packages using apt-get?

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.


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 using one of the following commands:

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

or

  1. xargs sudo apt-get install < pkglist

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


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

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^