DEBIAN_FRONTEND环境变量


22

我潜在的托管服务提供商建议在终端中运行命令,以使基于KVM的服务器的OS映像最小化。由于它们不需要KVM模板,因此我想可以使用相同的命令删除不需要的软件包。

该命令以开头DEBIAN_FRONTEND=noninteractive,然后apt-get remove按以下方式调用:

DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" package-1 package-2 ... package-n; apt-get -y autoremove; apt-get clean all 

这是我第一次遇到DEBIAN_FRONTEND环境变量,到目前为止,我找不到有用的信息。因此,我想知道将其设置为noninteractive做什么,以及是否建议这样做,因为我认为值(noninteractive)会持续存在。


4
不知道它的作用,我可以说,当您以这种方式将变量设置为较长的​​命令字符串的一部分时,它仅在运行该命令时有效。它不会持续。
Gunnar Hjalmarsson

Answers:


27

简单地在前面加上一个apt命令DEBIAN_FRONTEND=something不会在应用单个命令之后继续存在。

这些DEBIAN_FRONTEND选项记录在的第7节手册页中debconf(您可能需要安装debconf-doc软件包才能在系统上使用它们)。来自man 7 debconf

Frontends
   One of debconf's unique features is that the interface it  presents  to
   you is only one of many, that can be swapped in at will. There are many
   debconf frontends available:

   dialog The default frontend, this uses  the  whiptail(1)  or  dialog(1)
          programs to display questions to you. It works in text mode.

   readline
          The  most  traditional frontend, this looks quite similar to how
          Debian configuration always has been:  a  series  of  questions,
          printed  out  at  the console using plain text, and prompts done
          using the readline library. It even supports tab completion. The
          libterm-readline-gnu-perl package is strongly recommended if you
          chose to use this frontend; the default readline module does not
          support  prompting  with default values.  At the minimum, you'll
          need the perl-modules package installed to use this frontend.

          This frontend has some special hotkeys. Pageup (or ctrl-u)  will
          go  back  to  the previous question (if that is supported by the
          package that is using debconf), and pagedown  (or  ctrl-v)  will
          skip forward to the next question.

          This is the best frontend for remote admin work over a slow con‐
          nection, or for those who are comfortable with unix.

   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.

它还指出:

   You can change the default frontend debconf uses by reconfiguring  deb‐
   conf.  On the other hand, if you just want to change the frontend for a
   minute, you can set the DEBIAN_FRONTEND  environment  variable  to  the
   name of the frontend to use. For example:

     DEBIAN_FRONTEND=readline apt-get install slrn

   The  dpkg-reconfigure(8) and dpkg-preconfigure(8) commands also let you
   pass --frontend= to them, followed by the frontend  you  want  them  to
   use.

   Note  that not all frontends will work in all circumstances. If a fron‐
   tend fails to start up for some reason, debconf will print out  a  mes‐
   sage explaining why, and fall back to the next-most similar frontend.

1
我看到了DEBIAN_FRONTEND=noninteractive常用的Dockerfiles。这个答案让我感到奇怪,为什么我们不直接在--yesapt命令中使用该标志,因为它会更加明确,并且在大多数情况下会满足我们的需求。
丹尼斯

@Dennis我认为这是因为不一定要安装readline,并且apt可以这样输出警告。
hayd

4
注意:如果DEBIAN_FRONTEND与with一起使用sudo,请在sudo命令中设置变量,而不是为此设置变量。即:sudo DEBIAN_FRONTEND=noninteractive apt-get install slrn。如果将env变量设置放在之前sudo,它将对sudo命令本身有效,并且sudo不会将其复制到apt-get正在运行的命令中。sudo在实际命令和命令之间使用它是sudo用于设置要运行的命令的env变量的语法(请参见手册页)。这让我很难受,所以我想分享。
caxcaxcoatl

1
如果要将前端默认行为更改为noninteractive,则可以使用以下命令执行此操作:dpkg-reconfigure debconf --frontend=noninteractive
Carter Pape
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.