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

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


Assuming this is stored in packages.txt, then run the following command:

xargs sudo apt-get install <packages.txt

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

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.

  • You missed the -y to avoid the apt-get asking confirmation from the user. Mar 15 at 5:57

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. Apr 29 '18 at 2:35
  • 1
    Using the accepted answer resulted in an aborted Y/n query of apt. Using this worked. Thanks! Dec 13 '19 at 19:00

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).


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)

  • 8
    This answer has accessibility issues: Text in images, can not be read by blind people. Aug 7 '18 at 9:32
  • Please, don't post images of text Also, consider explaining what's special about your answer. There are other answers that are almost identical to yours.
    – Kusalananda
    Mar 13 at 21:42

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.