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


21

如果我运行:

sudo apt-get --yes install postfix 

要么

sudo bash -c 'yes | apt-get --yes install postfix'

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

有什么魔术让我无需人工干预即可安装postfix(和其他软件包)的?

Answers:


32

设置DEBIAN_FRONTENDnoninteractive

DEBIAN_FRONTEND=noninteractive apt-get ...

这也适用于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.

如果您设置好了noninteractive,应该考虑debconf使用回答问题debconf-set-selections


1
请注意,用 man 7 debconf在Ubuntu 16.04,你需要先安装debconf-doc,例如sudo apt-get install debconf-doc
the_velour_fog

@the_velour_fog或单击上面的联机帮助链接,然后在打开的页面中单击16.04。
muru
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.