これは、なにをしたくて書いたもの?
Ubuntu LinuxのようなDebian系のLinuxディストリビューションで、パッケージのインストール時に選択画面が
現れることがあります。
これが現れると、選択を進めない限りパッケージのインストールがそこで止まってしまうのでなんとかしたい
という話です。
例
たとえばUbuntu Linux 24.04 LTSでEmacsをインストールしようとすると
$ sudo apt install emacs
こういう画面が現れます。

これはPostfixの設定に関するもので、この中から選択する必要があります。
Postfixを使いたいわけではないので「No configuration」を選ぶのですが、環境構築の自動化とはとても相性が
悪いです。
これをなんとかしたいという話ですね。
なお、Emacsのインストール時に--no-install-recommendsオプションをつけておけばそもそもPostfixは
インストールされませんよ、とかPostfixをあとでアンインストールすればいいのではという話はここでは
置いておきます。
環境
今回の環境はこちら。
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 24.04.3 LTS Release: 24.04 Codename: noble $ uname -srvmpio Linux 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
aptを非インタラクティブに実行するには?
apt(またはapt-get)を非インタラクティブに実行するには、DEBIAN_FRONTEND環境変数にnoninteractiveを
指定します。
たとえば、以下のように指定します。
$ sudo DEBIAN_FRONTEND=noninteractive apt install emacs
こうすると選択画面自体が表示されなくなり、デフォルト値を選択したことになります。
DEBIAN_FRONTEND環境変数は、debconfパッケージのドキュメントに説明があります。
Ubuntu Manpage: debconf - Debian package configuration system
デフォルト値はdialogで、これが選択画面を表示していわけですね。
選択結果の確認方法と設定方法
とはいえ、選択画面が出なくなればよいわけではありません。選択肢がわかっているのであれば、値は明示的に
指定したいですね。
この選択結果はdebconf-get-selectionsコマンドで確認できます。これはdebconfのデータベースの内容を出力する
コマンドです。
Ubuntu Manpage: debconf-get-selections - output contents of debconf database
このコマンドはデフォルトでは入っておらず、debconf-utilsパッケージに含まれています。
$ sudo apt install debconf-utils
実行すると、多数の値が表示されます。
$ sudo debconf-get-selections # Additional home directory locations: apparmor apparmor/homedirs string # Do you want to add the group ? base-passwd base-passwd/group-add boolean true # Do you want to change the GID of group ? base-passwd base-passwd/group-change-gid boolean true # Do you want to move the group ? base-passwd base-passwd/group-move boolean true # Do you want to remove the group ? base-passwd base-passwd/group-remove boolean true # Do you want to add the user ? base-passwd base-passwd/user-add boolean true 〜省略〜
今回のPostfixに関する情報で絞り込んでみましょう。
$ sudo debconf-get-selections | grep -i postfix postfix postfix/bad_recipient_delimiter error postfix postfix/chattr boolean false postfix postfix/destinations string $myhostname, server, localhost.localdomain, , localhost postfix postfix/mailbox_limit string 0 postfix postfix/mailname string server postfix postfix/main_mailer_type select Internet Site postfix postfix/mynetworks string 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 postfix postfix/newaliases boolean false # Postfix not configured postfix postfix/not_configured error postfix postfix/procmail boolean false postfix postfix/protocols select all postfix postfix/recipient_delim string + postfix postfix/relayhost string postfix postfix/rfc1035_violation boolean false postfix postfix/root_address string
内容を見る限り、選択画面で聞かれていたのはこれですね。
postfix postfix/main_mailer_type select Internet Site
では、こちらの値を設定します。使うのはdebconf-set-selectionsコマンドです。これはdebconfデータベースに
値を設定するコマンドです。
Ubuntu Manpage: debconf-set-selections - insert new values into the debconf database
debconf-set-selectionsコマンドはdebconfパッケージに含まれているので、追加でインストールすることはないと
思います。
たとえば選択肢でNo configuration'を選択したいとしましょう。

その場合は以下のように設定します。
$ echo "postfix postfix/main_mailer_type select No configuration" | sudo debconf-set-selections
確認。
$ sudo debconf-get-selections | grep -i postfix postfix postfix/main_mailer_type select No configuration
この状態で非インタラクティブモードでパッケージをインストールすると
$ sudo DEBIAN_FRONTEND=noninteractive apt install emacs -y
選択画面で「No configuration」を選んだのと同じ状態になります。
$ sudo debconf-get-selections | grep -i postfix postfix postfix/bad_recipient_delimiter error postfix postfix/chattr boolean false postfix postfix/destinations string postfix postfix/mailbox_limit string 0 postfix postfix/mailname string /etc/mailname postfix postfix/main_mailer_type select No configuration postfix postfix/mynetworks string 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 postfix postfix/newaliases boolean false # Postfix not configured postfix postfix/not_configured error postfix postfix/procmail boolean postfix postfix/protocols select postfix postfix/recipient_delim string + postfix postfix/relayhost string postfix postfix/rfc1035_violation boolean false postfix postfix/root_address string
おわりに
Ubuntu Linux 24.04 LTSで、debconf-set-selectionsコマンドとDEBIAN_FRONTEND環境変数を使って
パッケージのインストール時の選択画面を表示しないようにしつつ、設定を行う方法をまとめてみました。
一応前からこの内容は少し知っていたのですが、Ubuntu Linux 24.04 LTSになってからEmacsのインストール時に
Postfixがついてくるようになってどうしたものかと思っていたのでこれを機にまとめておくことにしました。
やっぱりちゃんと見ないと理解がざっくりしたままので、こういう機会も大事ですね。