How to prevent prompt that ask to restart services when installing libpq-dev

27,169

Solution 1

Set the environment variable DEBIAN_FRONTEND=noninteractive.

For example:

export DEBIAN_FRONTEND=noninteractive
apt-get install -y libpq-dev

This will make apt-get select the default options.

Solution 2

You should be able to achieve this using debconf-set-selections. From the man page:

debconf-set-selections can be used to pre-seed the debconf database
with answers, or to change answers in the database. Each question will
be marked as seen to prevent debconf from asking the question
interactively.

In order to determine the required input to debconf-set-selections if unknown, you can answer the prompt manually and then inspect the debconf database to find the correct value. To do this, install debconf-utils:

sudo apt-get -y install debconf-utils

which provides the debconf-get-selections command. Then:

sudo debconf-get-selections | grep libssl1.0.0:amd64

to check the values in the database. On my system (Ubuntu, but Debian should be similar) I am not prompted when I apt-get install libpq-dev, and I have this entry:

libssl1.0.0:amd64   libssl1.0.0/restart-services     string

so you should be able to use:

echo 'libssl1.0.0:amd64 libssl1.0.0/restart-services string' | sudo debconf-set-selections

to set the list of services to restart when upgrading libssl to 'none'.

Under Debian, there should be more information about valid values for this line in the questions.dat file under /var/lib/cdebconf. See https://www.debian.org/releases/stable/i386/apbs03.html.en for more details.

Solution 3

I think the existing answers may be a bit old. The following worked for me recently.

To see the settings for a package

sudo debconf-show <package-name>

E.G:

$ sudo debconf-show libssl1.1 
  libssl1.1/restart-services:
  libssl1.1/restart-failed:
* libraries/restart-without-asking: false

To change the setting

echo '<package-and-setting-string>' | sudo debconf-set-selections

E.G

echo 'libssl1.1 libraries/restart-without-asking boolean true' | sudo debconf-set-selections

Bonus tip, to set this setting for all packages use '*' in place of the package name.

E.G

echo '* libraries/restart-without-asking boolean true' | sudo debconf-set-selections

Solution 4

You can disable this feature on Debian 11 by uninstalling the needrestart package.

apt remove needrestart
Share:
27,169

Related videos on Youtube

OrangeTux
Author by

OrangeTux

Updated on September 18, 2022

Comments

  • OrangeTux
    OrangeTux over 1 year

    I want to install libpq-dev on my Vagrant machine. I install it with

    $ apt-get install -y libpq-dev
    

    During installation a prompt appears which asks if it's allowed to restart some services automatically. This prompt breaks my Vagrant provision. How can disable this prompt?

    prompt

    Text:

    There are services installed on your system which need to be restarted when certain libraries, such as libpam, libc, and libssl, are upgraded. Since these restarts may cause interruptions of service for the system, you will normally be prompted on each upgrade for the list of services you wish to restart. You can choose this option to avoid being prompted; instead, all necessary restarts will be done for you automatically so you can avoid being asked questions on each library upgrade.

    ****EDIT ****

    Thanks to Patrick's answer and this question I fixed it. Now my Vagrantfile contains:

     sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libpq-dev
    
    • Marek Zakrzewski
      Marek Zakrzewski almost 10 years
      I was suggesting to use -y but seems it doesn't change much. see man apt-get | less +/--force-yes
    • OrangeTux
      OrangeTux almost 10 years
      I've tried that optiont too, but that didn't worked either.
    • Niklas Mertsch
      Niklas Mertsch over 3 years
      Maybe a bit late, but -y is an option for apt-get, but the prompt in question comes from dpkg, the package management backend used by apt. DEBIAN_FRONTEND is read by dpkg, that's why it works in this case and -y does not.
  • Nigel Horne
    Nigel Horne almost 5 years
    Doesn't work in this case.
  • phemmer
    phemmer almost 5 years
    Please specify what "this case" is. The author of the question has selected this answer as correct. If the answer does not work for you, I recommend you ask a new question and make sure to clarify how your case is different, and that this does not work for you.
  • Felipe
    Felipe almost 5 years
    It didn't work for me neither.
  • Nicholi
    Nicholi over 4 years
    Is the default option to restart the service or not restart the service?
  • RSHAP
    RSHAP over 4 years
    didn't work for me either - export DEBIAN_FRONTEND=noninteractive; sudo apt-get update; sudo apt-get install -y libssl-dev openssl. ubuntu 18
  • bradj
    bradj over 4 years
    The accepted answer did not work for me but using debconf-set-selections did.
  • spikyjt
    spikyjt about 4 years
    @RSHAP that's because you have exported the DEBIAN_FRONTEND variable in your shell, but the executed the commands with sudo. This answer describes running the commands as root. When using sudo you will need to prefix each command with the environment variable, instead of exporting it, e.g. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libssl-dev openssl