如何以非交互方式安装 apt 软件包?

use*_*956 30 apt postfix

如果我运行:

sudo apt-get --yes install postfix 
Run Code Online (Sandbox Code Playgroud)

或者

sudo bash -c 'yes | apt-get --yes install postfix'
Run Code Online (Sandbox Code Playgroud)

出现交互式提示以配置后缀。我需要自动安装postfix(我可以在安装后修改配置文件)。

是否有一些魔法可以让我在没有人工干预的情况下安装 postfix(和其他包)?

mur*_*uru 42

设置DEBIAN_FRONTENDnoninteractive

DEBIAN_FRONTEND=noninteractive apt-get ...
Run Code Online (Sandbox Code Playgroud)

这也适用于dpkg --reconfiguredpkg-configure等等。

来自man 7 debconf

noninteractive
      This  is  the anti-frontend. It never interacts with you at all,
      and makes the default answers be  used  for  all  questions.  It
      might  mail  error messages to root, but that's it; otherwise it
      is completely silent and unobtrusive,  a  perfect  frontend  for
      automatic installs. If you are using this front-end, and require
      non-default answers to questions, you will need to  preseed  the
      debconf  database;  see  the section below on Unattended Package
      Installation for more details.
Run Code Online (Sandbox Code Playgroud)

如果确实设置了noninteractive,则应考虑debconf使用debconf-set-selections.

  • 请注意,要在 ubuntu 16.04 上使用 `man 7 debconf`,您需要首先安装 `debconf-doc`,例如 `sudo apt-get install debconf-doc` (2认同)