如何以非交互方式安装apt软件包?
如果我跑:
sudo apt-get --yes install postfix
要么
sudo bash -c 'yes | apt-get --yes install postfix'
出现交互式提示以配置postfix。 我需要自动安装postfix(我可以在安装后修改配置文件)。
是否有一些魔法可以让我在没有人为干预的情况下安装postfix(和其他软件包)?
将DEBIAN_FRONTEND
设置DEBIAN_FRONTEND
noninteractive
:
DEBIAN_FRONTEND=noninteractive apt-get ...
这也适用于dpkg --reconfigure
, dpkg-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.
如果你设置了noninteractive
,你应该考虑使用debconf-set-selections
来回答debconf
问题。