I am mass installing apt-get packages from a "packages.txt" (or call it what you like) as explained at Using a file to install packages with apt-get.

Commenting out "terminator" apt package:


throws an error:

The command '/bin/sh -c xargs -a /tmp/packages.txt apt-get install -y' returned a non-zero code: 123

In contrast, if you fill a "requirements.txt" for a Python instead like here in a Dockerfile, it ignores each line starting with #.

RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /tmp/requirements.txt

with "requirements.txt":


Result: mysql-server is skipped.

How would I comment out an apt package in a "packages.txt"?

2 Answers 2


Filter the list of packages before feeding it to xargs:

grep -v '^#' /tmp/packages.txt | xargs -r sudo apt-get install -y

Adding -r to the xargs invocation ensures that nothing happens if all lines in packages.txt are commented out.


If you would want to escape the handling of plain text file packages.txt, I developed the sysdep tool just for this exact purpose. It is a simple tool that reads from a toml file instead of a plain text file. This allow the flexibility of toml file for apt packages similar to pyproject.toml, cargo.toml.

  1. Download with

    curl -L https://github.com/Benjamin-Tan/sysdep/releases/latest/download/sysdep-$(arch)-unknown-linux-gnu.tar.gz | tar -xz -C ~/.local/bin
  2. Create a system_dependencies.toml

    apt = ["libpackage", "libpackage2"]
  3. sysdep list to list the dependencies, should display 'libpackage', 'libpackage2'.

  4. sysdep install to install them

  5. sysdep to display the help page for more options.

  • Welcome here but sorry, I fail to understand how this would answer OP's precise question. And would it help, wouldn't all this be far more complicated than the accepted answer ?
    – MC68020
    Apr 3 at 11:47
  • This would allow mass install the packages from a file, and able to put comments at the same time. Apr 3 at 12:13
  • Can you add an example of how to use comments, then?
    – muru
    Apr 3 at 15:02
  • "Sysdep": "A simple system dependency tool to list/install the apt/pip dependencies based on a toml file, written in Rust. The goal of this tool is to allow developer to specify the system dependencies of any project that has software packages written in various programming languages (C, C++, Python)." This answer is a hole in one. For those who search for an example, see the link in the answer which shows some sysdep examples. The answerer is the writer of "sysdep". Apr 3 at 16:30
  • @questionto42 as I have explained to the answerer elsewhere, the point of adding relevant information in the answer is so that we can know the link is relevant to the problem and worth visiting.
    – muru
    Apr 3 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .