Explain DEBIAN_FRONTEND apt-get variable for Ubuntu / Debian

Can you explain DEBIAN_FRONTEND apt or apt-get variable? How and why I need to use this in Docker or shell scripts under a Debian and Ubuntu Linux?

Debian, Ubuntu, and clones use the Debian package configuration system called debconf. One can use debconf before packages installed onto your Linux desktop or cloud server. For example, one can configure the apt command or apt-get command using various options for sysadmin tasks. This page explains DEBIAN_FRONTEND environment variable.


Explain DEBIAN_FRONTEND apt-get variable

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:

  1. dialog – The default frontend for apt/apt-get under Debian/Ubuntu Linux. It displays questions to you. It works in text mode over ssh based session.
  2. readline – The most traditional frontend, this looks quite similar to how Debian configuration options are: a series of questions, printed out at the console using plain text. Best suited when you are working with slow remote connections and entirely comfortable with Linux command-line options.
  3. noninteractive – You use this mode when you need zero interaction while installing or upgrading the system via apt. It accepts the default answer for all questions. It might mail an error message to the root user, but that’s it all. Otherwise, it is totally silent and humble, a perfect frontend for automatic installs. One can use such mode in Dockerfile, shell scripts, cloud-init script, and more.
  4. gnome – This is a modern X GUI using the gtk and gnome libraries.
  5. kde – Another frontend provides a simple X GUI written with the Qt library. It fits well the KDE desktop.
  6. editor – This is for those fanatics who have to do everything in a text editor. It runs your editor on a file that looks something like a typical unix config file, and you edit those files to communicate with debconf.
  7. web – This frontend acts as a web server, that you connect to with your web browser, to browse the questions and answer them. Again it is a proof of concept, and one should avoid using web frontend for security reasons.

How to use apt DEBIAN_FRONTEND environment variable

The syntax is as follows:
DEBIAN_FRONTEND={name_here} apt-get install pkg
DEBIAN_FRONTEND={name_here} apt install pkg
DEBIAN_FRONTEND=noninteractive apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade

For longer scripts and other swapping process you may want to export shell variable:
export DEBIAN_FRONTEND=noninteractive
apt -y install nginx
apt-get -y update
apt-get -y upgrade

AWS EC2/Lightsail example

One can run script using Linode or AWS or service providers cloud-init system. In other words add a shell script that will run on your instance the first time it launches on AWS Lightsail:
Ubuntu Debian DEBIAN_FRONTEND=noninteractive Linux script on AWS EC2
For EC2 run aws cli as follows:
aws ec2 run-instances --image-id ami-abcd1234 --count 1 \
--instance-type m3.medium --key-name my-ssh-key \
--subnet-id subnet-abcd1234 --security-group-ids sg-abcd1234 \
--user-data file://ubuntu-server-script.txt


You can write and use a script to configure your VM when it starts up. These scripts can add software, update software, or configure your instance in some other way on Linode:
Explain DEBIAN_FRONTEND apt-get in Debian or Ubuntu Linux on Linode

Sample shell script

The following script force apt-get to skip any interactive post-install configuration steps and do other stuff too before we can use Ansible for other stuff:

## Tested for AWS only. May need modification and subnet for other cloud hosting providers
## Author: Vivek Gite, under GPL v2.+ {https://www.cyberciti.biz/}
## ------------------------------------------------------------------------------------------
## admin_IP_1|short_description_1 admin_IP_2|short_description_2
## set server hostname, we can get it from gcp/aws conf too
## update system when vm creted via cloud-init ##
export DEBIAN_FRONTEND=noninteractive
apt-get -y update
apt-get -y upgrade
## set hostname ##
hostnamectl set-hostname "${_hostname}"
## get security settings ##
wget -q -O /etc/sysctl.d/1000-custom.conf https://www.cyberciti.biz/files/1000-custom.conf
## enable firewall ##
yes | ufw enable 
## open ssh port to our admin ips only ##
for e in $_admin_ip
  ufw allow from "${e%%|*}" to any port 22 proto tcp comment 'Open SSH port for ${e##*|}'
## extra rule allow vpc 
ufw allow from to proto any comment 'Allow communitcation between AWS VPC peers'
ufw allow from to proto any comment 'Allow communitcation between AWS VPC peers'
## sync and reboot vm ##
## Rest config will be done by Ansbile ##


You learned how to use DEBIAN_FRONTEND to change the frontend debconf uses temporarily. See debconf and apt-get man pages for more information.
man 7 debconf
man 8 apt
man 8 apt-get

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.