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
  • 2
  • 6
  • 14
  • possible duplicate of [How do I make post-install scripts?](http://askubuntu.com/questions/47404/how-do-i-make-post-install-scripts) – Alvar Oct 26 '14 at 09:08

3 Answers3

35

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.

Pandya
  • 34,843
  • 42
  • 126
  • 186
  • 5
    If you want this to install along any requirements you'll have to do `xargs sudo apt-get -y install < pkglist` – Emanuel Ey Apr 13 '16 at 17:31
  • 2
    +1 If you list one package per line, the file **must** use Unix line endings or apt-get will fail. – rath Sep 09 '18 at 12:52
  • You can also pass the filename directly to xargs with the -a or --arg-file option: `xargs -a pkglist sudo apt install`. – Ryan Dec 30 '18 at 15:48
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,872
  • 7
  • 48
  • 78
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
  • 77,204
  • 56
  • 214
  • 254
  • 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