5

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.

2

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
  • Thanks, how can I stop apt-get from asking me Y/n questions whether I really want to install the package? – syntagma Oct 26 '14 at 9:13
  • 1
    Add the -y option. It's pretty long, but you can read man apt-get for more information. – Sparhawk Oct 26 '14 at 9:13
20

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 that packages by apt using following command:

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

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

  • 2
    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
  • +1 If you list one package per line, the file must use Unix line endings or apt-get will fail. – rath Sep 9 '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
1

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^
  • 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 0:22

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.