APT – Using a File to Install Packages with apt-get

aptsoftware installation

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…

?

Best Answer

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

iceweasel
terminator
vim

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.

Related Question