Auto yes to the License Agreement on sudo apt-get -y install oracle-java7-installer

UbuntuAutomationApt

Ubuntu Problem Overview


The Oracle Java package for Ubuntu interactively asks about the License Agreement. So I have to say 'OK' and then 'yes' every time, but I'd like to automate it. What I do is this:

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java7-installer 

Is there a simple way to automate the agreement process without using expect?

Ubuntu Solutions


Solution 1 - Ubuntu

try this out:

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java7-installer 

running 3rd and 4th command on my debian 7.1 helps, so I think the same can help on ubuntu as well

Solution 2 - Ubuntu

If you are using Ansible for automation you may want to put this into your playbook:

tasks:

  - name: add java PPA
    apt_repository:
      repo: "ppa:webupd8team/java"

  - name: accept oracle license
    debconf:
      name: "oracle-java7-installer"
      question: "shared/accepted-oracle-license-v1-1"
      value: "true"
      vtype: "select"

  - name: install jdk
    apt:
      name: "oracle-java7-installer"

Note: The value argument in debconf must be set to "true", including the quotes, as per comment by Roy Wood.

Solution 3 - Ubuntu

ppa:linuxuprising/java && oracle-java11-installer

For anyone using the Linux Uprising Java 11 installer that stumble across this, see these:

  1. https://launchpad.net/~linuxuprising/+archive/ubuntu/java
  2. https://www.linuxuprising.com/2018/10/how-to-install-oracle-java-11-in-ubuntu.html

Instead of the commands in the answer (as listed on their site), you want this:

echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | \
sudo /usr/bin/debconf-set-selections

Here's my Docker setup for an Ubuntu 18.04-based container:

RUN apt-get update && apt-install -y software-properties-common && \
    add-apt-repository -y ppa:linuxuprising/java && \
    apt-get update && \
    echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | sudo /usr/bin/debconf-set-selections && \
    apt-get install -y oracle-java11-installer && \
    apt install oracle-java11-set-default

Solution 4 - Ubuntu

For Java 11 you can use this:

add-apt-repository ppa:linuxuprising/java
echo debconf shared/accepted-oracle-license-v1-2 select true | debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-2 seen true | debconf-set-selections
apt-get update && apt-get install -y oracle-java11-installer

This works perfectly in a docker container.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkojiwellView Question on Stackoverflow
Solution 1 - UbuntuMaxymView Answer on Stackoverflow
Solution 2 - UbuntuschromView Answer on Stackoverflow
Solution 3 - Ubuntuel n00bView Answer on Stackoverflow
Solution 4 - UbuntuKireByteView Answer on Stackoverflow