Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For most packages that require a yes/no answer, this works fine for me:

sudo apt-get install -y ....

But if you require a package that makes you accept a license, how do you automatically agree to that?

For example, sun java:

sudo apt-get install -y sun-java6-bin sun-java6-jdk sun-java6-jre sun-java6-plugin

This requires me to select OK, and then yes.

share|improve this question
Just some info: the sun flavored java has just been removed from debian. So you are running an unsupported program and you will not get security updates. (This also applies to ubuntu because of license restrictions).… You should take a look at openjdk. – cstamas Nov 1 '11 at 9:23

There are some ways to do this:

  1. Pre-answer with debconf by executing the following command before installing:

    echo sun-java6-jdk shared/accepted-sun-dlj-v1-1 select true | \
  2. Use expect:

    #!/usr/bin/expect -f
    sudo apt-get -y install sun-java6-jre
    expect "[y/n]"
    sleep 1
    send -- "yes\r"
share|improve this answer
so would you put that echo line after the apt-get install line? – codecompleting Nov 1 '11 at 20:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.