关闭ubuntu22.04的Daemons using outdated libraries服务重启提示弹窗

在一个全新安装的Ubuntu 22.04 LTS上,每次使用apt安装或更新软件包时,会出现一个 Daemons using outdated libraries 弹窗,Which service should be restarted ? 大概是下面这个样子:

img

这是Ubuntu 22.04中的新功能。它是由 needrestart 命令带来的新特性,needrestart 现在是Ubuntu中apt-get升级过程的一部分。默认情况下,此设置为 “interactive” (交互式)模式,会导致脚本中断

修改这个模式配置,我们编辑 /etc/needrestart/needrestart.conf 文件,找到下面的这行:

1
2
3
4
5
6
# 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';

三个配置:

1
2
3
4
5
6
# i: 交互提示重新启动(默认值)
i: prompt interactively for restarts (default value)
# a: 自动重启
a: restart automatically
# l: 列出需要重启的服务
l: list needed restarts

直接修改成:

1
$nrconf{restart} = 'a'