Imagine you are developing an application which runs on Linux (I'm using Ubuntu) and requires a number of packages to be able to run.

One way would be to just install the packages as needed, but sooner than later, you'll forget which packages are needed. It becomes an even bigger problem when you want to install the same set of packages on your production systems.

Therefor, the approach I take is to keep a file called packages.list as part of the source repository in which I keep track of the packages I need. It's largely inspired on the requirements.txt approach often found in Python projects.

The content is simple: one package per line.

packages.list:

# Movie processing
ffmpeg
# PDF processing
mupdf-tools
poppler-utils
qpdf

Now, it would be very easy to have a single command to use apt to install / update these packages on any system. Well, here is a command that will do exactly that:

sudo apt install -y $(grep -o ^[^#][[:alnum:]-]* "packages.list")

The grep command filters out all invalid lines (e.g. the ones which are commented out) and then uses apt install to install them on the system.

Related Posts

  • SSH Tunnel
  • Checking websockets with cURL
  • TIL: combining PDF files via the command line
  • Setting up an NFS share on Linux
  • Get the absolute path of a bash script