8

I find it very convenient to install packages on a new machine through package files like brewfiles, caskfiles, dockerfiles, package.json etc.

Is there an alternative to this for apt-get since I still just use it
through commandline with

apt-get install pkg1 pkg2 pkg3…

?

  • 2
    Does it need one? You could use xargs: xargs -P1 apt-get install < list-of-packages. – muru Jan 19 '15 at 10:26
  • @muru well I don't really know how xargs works (reading man now) but I don't think that is a solution to having the packages centralised in one file? I would still have to manually list the files after the < since using a .txt file with three packages in it doesn't work with this command (tested on Debian) – thibmaek Jan 19 '15 at 12:29
  • 1
    the < is shell redirection. For multiple files, use: cat file1 file2 .. | xargs -P1 apt-get install – muru Jan 19 '15 at 12:32
12

As specified in the comments of your question, you can build a simple text file, called packages.txt, listing the packages to install:

iceweasel
terminator
vim

and then run the following command:

cat packages.txt | xargs sudo apt-get install

xargs is used to pass the package names from the packages.txt file to the command line. From the man page:

xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial- arguments followed by items read from standard input.

8

Improving a bit on the answer of @ortomala-lokni, you can give the file directly as an argument to xargs:

xargs -a packages.txt sudo apt-get install

Optionally you can give xargs the -r option to prevent the apt-get call from being run at all if your packages.txt does not contain any non-whitespace characters.

  • This may be a peculiarity of Alpine / BusyBox, but the -a arg wasn't documented and didn't seem to work there: xargs: unrecognized option: a. My version output shown is BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary. – Taylor Edmiston Apr 29 '18 at 2:35
0

enter image description here

it works both the ways for me, make sure you have latest xargs, or otherwise check whether it has the -a option or not with help option(xargs --help)

  • 2
    This answer has accessibility issues: Text in images, can not be read by blind people. – ctrl-alt-delor Aug 7 '18 at 9:32
0

As well as the more general scripting solutions, you can create a deb package.

you will need

  • equivs-build, to build the deb. The deb can only contain dependencies. This is a simplified deb builder.
  • gdebi to install the deb.

This will work on all debian based systems (systems that use apt/deb-files).

The advantage of doing it with deb files, as opposed to a shell script, is that it is much easier to undo, you can uninstall a deb, or re-configure a deb, and re-install it (this will cause files to be added and removed).

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.