Home > Blockchain >  How to make apt-get upgrade -y not interactive
How to make apt-get upgrade -y not interactive

Time:07-24

I am trying to write a script to provision a new server. It is important that all the commands in the script do not require user interaction. I want to run the command: apt-get upgrade -y. I have noticed when I issue this command directly (ie. not in a script), a pop-up appears in my terminal:

enter image description here

Is there an option, or perhaps an alternative command that upgrades packages without needing this user interaction? I imagine if I put the command in a script the script would stop at this point and never resume.

I could also not see how to add an asterisk to a line which I presume indicates you want to restart that service. However, that is a different matter...

CodePudding user response:

apt-get -y upgrade, apt-get -y install [package], etc. automatically assumes "yes" to boolean yes/no prompts. Unfortunately, when more complex options are presented (e.g., service selections) and/or when no defaults are available to select, -y doesn't ensure non-interactivity.

Check out debconf-get-selections and debconf-set-selections (in Debian, the debconf-utils package). Typically, to automate selections for future headless/non-interactive installations, one can:

  1. Select the desired options in an interactive session (one-time);
  2. Run debconf-get-selections to get the correct represetation of the setting (e.g., debconf-get-selections | grep "^$package" to obtain the correct representation to feed back to debconf-set-selections: tab-delimited package, setting index, type, and setting); and,
  3. Script the setting using debconf-set-selections (e.g., echo 'wireshark-common wireshark-common/install-setuid boolean true' | debconf-set-selections).

Hope this helps.

CodePudding user response:

In your script, before calling any apt command, you could do the following:

export DEBIAN_FRONTEND=noninteractive

Note that the answer from ahi324 is usually better. While it would require more work / be exhaustive in which options to select, and maintain that configuration over time (rarely changes, still there could be new settings to add or old ones to rename).

The noninteractive would consistently skip all those questions.

  • Related