53

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?

kakabali
  • 3,824
  • 2
  • 29
  • 58
kojiwell
  • 872
  • 1
  • 10
  • 10
  • Since you're asking about the usage of the *Ubuntu/Debian* package manager, your question would better fit on [*Ask Ubuntu*](http://askubuntu.com/about) or [*Unix & Linux Stack Exchange*](http://unix.stackexchange.com/). – zakinster Oct 10 '13 at 13:02
  • On askubuntu: http://askubuntu.com/questions/190582/installing-java-automatically-with-silent-option – Ciro Santilli OurBigBook.com Jan 25 '15 at 22:05

5 Answers5

111

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

Maxym
  • 11,836
  • 3
  • 44
  • 48
  • @KJTanaka: you are welcome! please consider to accept it as a solution then ;) or ask more details if it does not solve your entire problem. thanks – Maxym Oct 20 '13 at 19:04
  • Part of it is documented online at Ubuntu's [add-apt-repository](http://manpages.ubuntu.com/manpages/trusty/man1/add-apt-repository.1.html), [apt-get](http://manpages.ubuntu.com/manpages/lucid/man8/apt-get.8.html) and [debconf](http://manpages.ubuntu.com/manpages/hardy/man7/debconf-devel.7.html) manuals. You can also use the command line to get the details. – Ashesh May 30 '15 at 08:02
  • A small note, the license number changes over time, I had to adjust to `v1-3`, surely it could increment again in the future. – quickshiftin Aug 04 '22 at 22:11
36

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.

jonatan
  • 9,011
  • 2
  • 30
  • 34
schrom
  • 1,372
  • 1
  • 22
  • 36
  • 3
    it also works with oracle-java8-installer using ```- name: accept oracle license debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'``` – DoRivard Jul 08 '15 at 15:22
  • 5
    Note that it's critical to use quotes on the debconf value! If you use just "value: true" in your playbook, then the value in the debconf database gets set to "True" and the silent installation will fail with the usual warning of "oracle-license-v1-1 license could not be presented". You have to specify "value: 'true' " in the playbook to ensure that the debconf setting is set to 'true', which is the exact string the Oracle installer looks for! – Roy Wood May 31 '17 at 15:08
  • I wish more system configuration questions were answered with Ansible syntax :D – jonatan Jun 21 '17 at 07:35
10

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
el n00b
  • 1,957
  • 7
  • 37
  • 64
  • 2
    I can confirm this answer also works for java 12. Note the license name is different than the accepted answer: v1-2, not v1-1. – Paul May 22 '19 at 19:04
  • Now it says `'oracle-java11-installer' has no installation candidate` – Khaled AbuShqear Jul 04 '20 at 02:23
  • And adding ppa `linuxuprising/java` didn't work with me, I used this fix: `echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A` – Khaled AbuShqear Jul 04 '20 at 02:24
3

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.

Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
KireByte
  • 31
  • 1
  • 2
1

Just like other answers, following works for the JDK 17

accepted-oracle-license-v1-3 - in specific

echo oracle-java17-installer shared/accepted-oracle-license-v1-3 select true | sudo /usr/bin/debconf-set-selections
kakabali
  • 3,824
  • 2
  • 29
  • 58