apt: change default answer from 'Y' to 'N'

On RPM Linux when installing anything, dnf‘s default answer in its simplest invocation is "N" (No) when prompted and the user will knowingly need to press "Y" (or "y") followed by Enter to install packages. Pressing simply Enter will abort the installation.

Doing the same on Debian-based systems, apt defaults to "Y" (Yes), which can have system-critical consequences if accidentally hitting Enter twice (especially since apt happily uninstalls packages in the same process if they conflict with the ones you want to install).

Therefore my question: Is it possible to make apt‘s prompt also default to "N"?

This should be a configuration and not an aliased command-line option since the systems are getting deployed.

Asked By: Phoenix

||

Poking in the sources:

      if (YnPrompt(_("Do you want to continue?")) == false)

various places rely on the function YnPrompt() for this:

// YnPrompt - Yes No Prompt.                      /*{{{*/
// ---------------------------------------------------------------------
/* Returns true on a Yes.*/
bool YnPrompt(char const * const Question, bool const Default, bool const ShowGlobalErrors, std::ostream &c1o, std::ostream &c2o)
{
...
bool YnPrompt(char const * const Question, bool const Default)
{
   return YnPrompt(Question, Default, true, c1out, c2out);
}

with Default defaulting to true:

// prompting
APT_PUBLIC bool YnPrompt(char const *const Question, bool Default = true);
bool YnPrompt(char const * const Question, bool const Default, bool const ShowGlobalErrors, std::ostream &c1o, std::ostream &c2o);

There’s a part to translate/localize the display of either [Y/n] or the less common [y/N] (which does exist, see example below) in various languages if the prompt is enabled:

   if (Default == true)
      // TRANSLATOR: Yes/No question help-text: defaulting to Y[es]
      //             e.g. "Do you want to continue? [Y/n] "
      //             The user has to answer with an input matching the
      //             YESEXPR/NOEXPR defined in your l10n.
      c2o << " " << _("[Y/n]") << " " << std::flush;
   else
      // TRANSLATOR: Yes/No question help-text: defaulting to N[o]
      //             e.g. "Should this file be removed? [y/N] "
      //             The user has to answer with an input matching the
      //             YESEXPR/NOEXPR defined in your l10n.
      c2o << " " << _("[y/N]") << " " << std::flush;

and then the part which retrieves the prompt’s input if an answer is not already forced by an APT configuration.

So the prompt depends on the value of the Default argument the function was called with.

There are only a few places where this argument is provided (to deviate from default [Y/n] prompt / Yes answer), and each time it’s directly provided as a constant: it doesn’t depend on any APT configuration. Example found in sources for apt-mark:

      if (YnPrompt(_("Do you want to continue?"), false) == false)

with false asking to prompt for [y/N], giving:

# apt-mark minimize-manual
The following packages will be marked as automatically installed:
[...]
Do you want to continue? [y/N] 
#

So there are APT configurations to avoid triggering such prompt like APT::Get::Assume-Yes or APT::Get::Assume-No to directly replace the prompt by Yes or No, or when using simulation (for last example: APT::Mark::Simulate) to not do anything nor prompt, but there doesn’t appear at least up to Debian 12’s apt version 2.6.1 to be any APT configuration to keep the prompt and change the default prompt/answer from [Y/n]/Yes to [y/N]/No, nor for that matter from [y/N]/No to [Y/n]/Yes.


Conclusion: currently this feature is not available. It could probably be made available by creating one or two new dedicated APT configuration parameters similar to how APT::Get::Assume-Yes and APT::Get::Assume-No work, that could be checked in YnPrompt() to alter how evaluation of the Default parameter passed is done. Or there could be other APT configuration parameters dedicated to a specific APT command (eg: apt-mark) to alter what this command will pass when querying YnPrompt(), but this doesn’t exist today.

Answered By: A.B
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.