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:
- 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.
- 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.
- 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.
- gnome – This is a modern X GUI using the gtk and gnome libraries.
- kde – Another frontend provides a simple X GUI written with the Qt library. It fits well the KDE desktop.
- 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.
- 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:
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
Stackscripts
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:
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:
#!/bin/bash ## 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 _admin_ip="1.2.3.4|MUM_ADM 3.2.4.5|DEL_IDC 6.7.8.9|VPN_SG_1" ## set server hostname, we can get it from gcp/aws conf too _hostname="server1.cyberciti.biz" ## 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 do ufw allow from "${e%%|*}" to any port 22 proto tcp comment 'Open SSH port for ${e##*|}' done ## extra rule allow vpc ufw allow from 172.26.0.0/16 to 172.26.0.0/16 proto any comment 'Allow communitcation between AWS VPC peers' ufw allow from 172.31.0.0/16 to 172.26.0.0/16 proto any comment 'Allow communitcation between AWS VPC peers' ## sync and reboot vm ## sync reboot ## Rest config will be done by Ansbile ##
Conclusion
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 Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |