Prevent Ubuntu 22.04 and newer from prompting during updates for restart

One of the more interesting additions that came with Ubuntu 22.04 is the needrestart package. When you perform package updates Ubuntu invokes this to determine how to handle restarting software that has been updated. The intention is to make sure that updates are downloaded and applied as soon as possible. This is important when software has a security vulnerability patched because it must be restarted for the fix to take effect. It generates prompts like this

For me what this means is that each time I run sudo apt-get full-upgrade I wind up seeing a prompt that I always toggle everything off. I always restart the machine after I install package updates. So I don't ever want to see this prompt and especially not an interactive one. Thankfully you can edit the file /etc/needrestart/needrestart.conf to modify this behavior. The default file contains a section like this

# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
#
# ATTENTION: If needrestart is configured to run in interactive mode but is run
# non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.
#
#$nrconf{restart} = 'i';

What we need to do is select a mode of "list only" by changing the file to look like this

# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
#
# ATTENTION: If needrestart is configured to run in interactive mode but is run
# non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.
#
$nrconf{restart} = 'l';

This change takes effect immediately


Copyright Eric Urban 2024, or the respective entity where indicated