2

When I am Running My Vagrantfile with its shell, I'm struggle with Java 8 install with this exact same error :

StackOverflow - jdk-8-is-not-installed-error-404-not-found

In order to fix that error, I added those lines :

sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*

I have in my Shell this block for java section:

# /*======================
# =            JAVA      =
# ======================*/
# https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-debian-8
sudo apt-get install -y software-properties-common
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
sudo apt-get update

# Silent !! Sshh !
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

# see https://stackoverflow.com/questions/46815897/jdk-8-is-not-installed-error-404-not-found
# Still not work
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*

sudo apt-get install -y oracle-java8-installer
sudo apt-get install -y oracle-java8-set-default

The weird thing is : Those lines taken one by one via SSH when the box is started and you can install Java, it Works. But it's not working when I provision for the first time my vagrant box.

Is the problem comes from sed or another command ? I suppose it's the sed's command but don't know how to fix it, because it's working if I paste them via SSH.

I want to make this work without any manual interventions.

You can test my VM using this github repo (V2) : VagrantFile + shells

How can I make this work using vagrant up ?

EDIT :

  • I've tested it on Vagrant 2.0 and virtualBox 5.6
  • Also tested with vagrant 1.7 and virtualBox 5.1
Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54
  • This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Jan 20 '18 at 16:19
  • Hum well thanks but I don't see how,, especially in vagrant context, the flow of informations is really massive – Greco Jonathan Jan 20 '18 at 19:19
  • Hi Hooli, do you explicitly want to use the webupd8team version of java-8? Otherwise I can write two alternatives for installing java-8 as answer below. The alternatives are to install the openjdk-8 version with apt-get or mount a folder containing the rpm package downloaded from oracle website and install this silently. – guicey Jan 23 '18 at 17:05
  • Hi I don't specifically want the webupd8team , I just want a functionnal version of JDK and JRE version without manual commands.If you make java work with it you'll earn the points :) – Greco Jonathan Jan 23 '18 at 18:26
  • Is there any reason that openjdk isn’t suitable. Does the oracle version give something extra? – Guy Jan 25 '18 at 02:13

4 Answers4

2

I'm putting this in just in case anyone is fine with Debians basic version, but has missed it. I think it should already be installed on anything but the most bare-bones systems.

To get openJDK working, which is the version offered in Debians standard repos, you would just need to use

apt-get install -y openjdk-8-jdk

There are other debug and docs packages as well.

Debian also provide a package in the contrib repos called java-package which converts the source tarball from the Oracle site (you have to get it yourself to OK the terms and conditions), and creates a deb from it. Unfortunately there doesn't seem to be a way to directly presume yes to the questions asked, so it would need an expect script or something.

config.vm.provision "shell", inline: <<-SHELL
    # add contrib repos into source files.
    mv /etc/apt/sources.list /etc/apt/sources.bk
    sed -r ‘s/stretch([^ ]*) main$/& contrib/‘ /etc/apt/sources.bk | sudo tee /etc/apt/sources.list
    # vi -c ':%s/stretch\([^ ]*\) main$/& contrib/g' /etc/apt/sources.list -c 'wq'
    apt-get update
    apt-get install -y java-package java-common expect
    # some `expect` needed magic here
    sudo -u vagrant fakeroot make-jpkg /vagrant/jdk-8*
    dpkg -i oracle-java8*
SHELL

In terms of the interactions I get using make-jpkg, this script works (from the command line)

expect -c '
set timeout -1
spawn fakeroot make-jpkg /vagrant/jdk-8u162-linux-x64.tar.gz

expect "Is this correct \\\[Y/n\\\]: $" { send "Y\r" }
expect "Press \\\[Return\\\] to continue: "  { send "\r" }
expect "*Press \\\[Return\\\] to continue or Ctrl-C to abort."      { send "\r" }
expect eof { exit 0 }
'

but could probably be done other ways.

So almost an answer, but may get you a bit closer.

Guy
  • 637
  • 7
  • 15
  • @Hooli I’ve just noticed it’s got using vi there. I’d actually used sed at that point, but aren’t on a proper computer now. Any error message? – Guy Jan 24 '18 at 21:00
  • default: E486: Pattern not found: stretch\([^ ]*\) main$ – Greco Jonathan Jan 24 '18 at 21:51
  • @Hooli sorry about that, replaced with sed now. You’ll have to check the expect command before running the whole thing automatically though, which would replace make-jpg in vagrantfile – Guy Jan 24 '18 at 23:57
  • Does this still work? Running ```sudo apt-get install openjdk-8-jdk``` gives me the error ```E: Unable to locate package openjdk-8-jdk``` – Karthik Sankaran Aug 26 '22 at 16:52
1

Sorry for my late answer. Another option is to mount a drive and install the oracle rpm package silently.

  1. Create directory and put there your Vagrantfile. This the root of your project. (./)

Vagrantfile

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.
  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "bento/centos-7.4"
  config.vm.boot_timeout = 240

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # View the documentation for the provider you are using for more
  # information on available options.
  config.vm.provider "virtualbox" do |vb|

    # Enable the Host I/O cache for more performance
    vb.customize [
                 "storagectl", :id,
                 "--name", "SATA Controller",
                 "--hostiocache", "on"
                 ]
    vb.auto_nat_dns_proxy = false
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"

    vb.customize ["modifyvm", :id, "--memory", 4096]
    vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
    vb.cpus = 4
  end

  # Synced folders are configured within your Vagrantfile using the config.vm.synced_folder method.
  # Vagrant shares by default the root directory of (./) with guest on /vagrant
  config.vm.synced_folder ".", "/vagrant", disabled: true

  # Synced folder is set as read-only for guest machine. You can configure the files on the host machine.
  # For more mount options check: http://manpages.ubuntu.com/manpages/precise/man8/mount.vboxsf.8.html
  config.vm.synced_folder "./installfiles", "/installfiles",
                           owner: "vagrant", group: "vagrant", mount_options: ["ro"]

  # Bootstrap shell scripts.
  config.vm.provision "shell", path: "./bootstrap/setup.sh"

  config.vm.post_up_message = "Finsihed provisioning!\n" \
                              "Type \"vagrant ssh\" to get started"
end
  1. Create another directory named bootstrap from the root of your project. Create an empty file called setup.sh, put the content below in the setup.sh file. The file path will be ./bootstrap/setup.sh

setup.sh

#!/usr/bin/env bash
echo "installing Java 8 64 bit"
sudo rpm -i /installfiles/java8/jdk-8u144-linux-x64.rpm
unzip /installfiles/java8/jce_policy-8.zip -d /tmp
sudo cp -f /tmp/UnlimitedJCEPolicyJDK8/* $JAVA_HOME/lib/security/
  1. Go to the oracle website download the correct 32 or 64 bit rpm linux package. Versions available on the oracle website might change. For this example i downloaded the jdk-8u144-linux-x64.rpm package. I also downloaded the unlimited encryption strength policy from the oracle website, name of the file is: jce_policy-8.zip.

  2. Create two directories from the root of your project named installfiles/java8. Place the downloaded files in there. The files path will be: ./installfiles/java8/jdk-8u144-linux-x64.rpm and ./installfiles/java8/jce_policy-8.zip

  3. Run the command vagrant up. On your host machine the directory ./installfiles will be synchronised with your virtualbox guest machine on the path /installfiles. During the provisioning state of vagrant java-8 will be installed automatically. Keep in mind that the rpm package manager comes out of the box with Red Hat distros. But it is also possible to install rpm packages on debian distros.

guicey
  • 686
  • 5
  • 14
0

The following snippet fixes the silent install of java from webupd8team repo for Debian distribution

sudo apt-get -y install software-properties-common
sudo add-apt-repository -y ppa:webupd8team/java
sudo bash -c "echo deb http://http.debian.net/debian jessie-backports main >> /etc/apt/sources.list"
sudo bash -c "echo deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo bash -c "echo deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
sudo apt-get -y upgrade

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-selectionssudo 

sudo apt-get -y install oracle-java8-installer oracle-java8-set-default

As of today, it installs the following

vagrant@debian-8:~$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • I will test, but far from i see you're using ubuntu which is very different in some ways for installing Java than Debian, wich is my first problem ;) – Greco Jonathan Jan 24 '18 at 16:44
  • oh right, I'll need to review, I thought you were using the scotch box which is ubuntu based; let me know the outcome of your test, I'll check from my side – Frederic Henri Jan 24 '18 at 16:46
  • If you can test to install this debian box : "bento/debian-8.7". Or best : use my actual vagrant file (link in the question) – Greco Jonathan Jan 24 '18 at 16:47
  • Tested, not working : default: E default: : default: Unable to locate package oracle-java8-installer – Greco Jonathan Jan 24 '18 at 20:36
  • updated script for Debian - tested with `bento/debian-8.7` vagrant box – Frederic Henri Jan 25 '18 at 10:24
  • It seems you have duplicated some code, is that wanted ? Which one to keep ? – Greco Jonathan Jan 25 '18 at 11:04
  • oops sorry ! this is some copy/paster issue, clean the script – Frederic Henri Jan 25 '18 at 12:17
  • It worked. But I don't understand why. Can you explain what the difference there is between my solution and yours ? We both use ppa:webupd8team/java. And if you can explain this part : --recv-keys EEA14886 – Greco Jonathan Jan 25 '18 at 18:46
  • ` default: Failed to fetch http://http.debian.net/debian/dists/jessie-backports/main/binary-amd64/Packages 404 Not Found [IP: 151.101.212.204 80] ` – Ray Kim Jul 16 '19 at 20:38
  • ` default: Duplicate sources.list entry http://ppa.launchpad.net/webupd8team/java/ubuntu/ trusty/main amd64 Packages (/var/lib/apt/lists/ppa.launchpad.net_webupd8team_java_ubuntu_dists_trusty_main_binary-amd64_Packages) ` – Ray Kim Jul 16 '19 at 20:38
  • ` default: Unable to locate package oracle-java8-installer ` – Ray Kim Jul 16 '19 at 20:38
  • ` default: Unable to locate package oracle-java8-set-default` – Ray Kim Jul 16 '19 at 20:38
  • @RayKim since Debian Jessie has been released Saturday, 23rd June 2018 you dont need to use `backports` anymore – Frederic Henri Jul 17 '19 at 07:50
0

Debian 9 "Stretch" has java 8 (jdk 1.8) as default jre. If you do not care about the debian version the following might work for you. I configured dabian/stretch64 as box. For me the -y flag worked to say yes to all questions. I have the following Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "debian/stretch64"
  config.vm.synced_folder ".", "/vagrant", disabled: true

  config.vm.provision "shell" do |s|
    s.inline = <<-SHELL
      sudo apt update
      sudo apt install default-jre -y
    SHELL
  end
Lady Bug
  • 11
  • 2