97

I am building a provisioning script for a ubuntu vagrant vm, on a ubuntu host, both 12.10 64bit When installing the following packages:

sudo apt-get -y install php5-xsl graphviz php-pear unison

I get the warning:

dpkg-reconfigure: unable to re-open stdin: No file or directory

have tried searching but results are throwing up every other error with apt-get possible, can't find out how to supress the warning above. The installs work, but the warning above is causing error lines in the vagrant up stdout.

Anybody any idea what could be the cause or how to suppress the warning

4 Answers 4

120

I got the error message to go away by putting the following in my provisioning script, prior to any apt-get calls:

export DEBIAN_FRONTEND=noninteractive

This makes debconf use a frontend that expects no interactive input at all, preventing it from even trying to access stdin.

4
  • 6
    This is the correct answer. Most config management applications (SaltStack, Puppet, etc) leverage this for non-interactive package installs.
    – notpeter
    May 4, 2015 at 19:25
  • 2
    Correct answer, I second that. May 31, 2015 at 17:54
  • 15
    It doesn't work for dpkg-preconfigure though.
    – kursus
    Nov 19, 2016 at 21:03
  • 2
    export DEBIAN_FRONTEND=noninteractive worked for me at the dpkg-preconfigure stage
    – Snowcrash
    Feb 22, 2019 at 11:19
25

The answer was to set the perl:locale's as per this:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

This solves the issue, but does add unwanted time to the vagrant up provisioning.

3
  • 2
    This alone did not work for me. I still got the warning until I implemented @kenorb's 70debconf commenting-out fix for preconfigure.
    – notbrain
    Aug 31, 2015 at 21:18
  • My question is: Is it fine to ignore these warnings? @Coombesy Sep 23, 2015 at 7:07
  • @MarcoPrins Yes, you can safely ignore warnings like "stdin: is not a tty" or "dpkg-preconfigure: unable to re-open stdin: No such file or directory". One of numerous confirmations around can be found, e.g. here ikusalic.com/blog/2013/10/03/vagrant-intro
    – mloskot
    Nov 1, 2015 at 18:22
10

Run this command:

cat /etc/apt/apt.conf.d/70debconf 

to see if you've this file. If so, the solution is to comment out the DPkg line which prevents pre-configuring all packages with debconf before they are installed.

So add these commands to your provision file:

sudo ex +"%s@DPkg@//DPkg" -cwq /etc/apt/apt.conf.d/70debconf
sudo dpkg-reconfigure debconf -f noninteractive -p critical

Otherwise if you don't care about this file, simply remove it:

sudo rm -v /etc/apt/apt.conf.d/70debconf

Here are few other commands to consider, but I don't think they do anything useful:

sudo dpkg-preconfigure -f noninteractive -p critical
sudo dpkg --configure -a
3
  • 1
    This is what finally worked for me on OSX Yosemite Vagrant and Ubuntu 14.04.
    – notbrain
    Aug 31, 2015 at 21:13
  • You may still need to change the shell Vagrant uses. Sep 2, 2015 at 19:23
  • 1
    Messing with this file was the only thing that worked for me (obviously ignoring the "redirect stderr" suggestions, which I think is bad advice). I elected to use a before/after pair of provisioning steps to temporarily include the --frontend=noninteractive option in the command defined in the file. sudo sed -i 's/\(dpkg-preconfigure\) --apt/\1 --frontend=noninteractive --apt/' /etc/apt/apt.conf.d/70debconf before, and sudo sed -i 's/ --frontend=noninteractive//' /etc/apt/apt.conf.d/70debconf after.
    – phils
    Jul 3, 2019 at 11:57
5

Bash redirection works fine for stdout and stderr.

To redirect the error stream, use the following:

sudo apt-get -y install php5-xsl graphviz php-pear unison 2> /dev/null

To redirect both stdout (messages that are not errors/warnings) and stderr both, use:

sudo apt-get -y install php5-xsl graphviz php-pear unison &> /dev/null

That is a shortcut available in bash for this:

sudo apt-get -y install php5-xsl graphviz php-pear unison > /dev/null 2>&1

Or:

sudo apt-get -y install php5-xsl graphviz php-pear unison 1> /dev/null 2>&1

Below, we can clearly see that file descriptor 1 is stdout, 2 stderr, 3 stdin.

$ ls -l /dev/std*
lrwxrwxrwx 1 root root 15 Apr 18 19:03 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Apr 18 19:03 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Apr 18 19:03 /dev/stdout -> /proc/self/fd/1

So for what you are saying you want to do, you should only need the very first command I gave.

2
  • 1
    I want to be able to echo the normal stdout from apt-get. But you may have me on the right track... i'll try sending just the stderr to the bit-bucket - cheers edit: we both commented at the same time lol - cheers (again)
    – Daithí
    Apr 19, 2013 at 1:34
  • I edited the post. See the very last line.
    – BullShark
    Apr 19, 2013 at 1:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .