1

I'm using Vagrant to simulate a network for a distributed system project. I'm using this file provision.sh in order to provision each machine in the cluster:

sudo apt-get update
sudo apt-get install -y openjdk-7-jdk
sudo apt-get purge -y openjdk-6-jre
sudo apt-get purge -y openjdk-6-jre-lib 
sudo apt-get install -y maven
echo "export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-i386" >> /home/vagrant/.profile
echo "export PATH=$JAVA_HOME/bin:$PATH" >> /home/vagrant/.profile
mvn clean -f /vagrant/RaftFS/pom.xml
mvn package -f /vagrant/RaftFS/pom.xml
sudo mv /vagrant/RaftFS/target/RaftFS-1.0-SNAPSHOT-jar-with-dependencies.jar /vagrant/
sudo cp /vagrant/RaftFS/servers.yaml /vagrant/

But when I access to the VM and I run java -version it says that the version 6 is still installed! How is that possible? As suggested by @ydaetskcoR if I execute env | grep JAVA_HOME it returns JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-i386 ...so I don't get why it says that the java version is 6

Just for completeness, this is the Vagrant file:

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

# Specify minimum Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"

# Require YAML module
require 'yaml'

# Read YAML file with box details
servers = YAML.load_file('RaftFS/servers.yaml')

# Create boxes
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Iterate through entries in YAML file
  servers.each do |key,value|
    config.vm.define key do |srv|
        srv.vm.box = value['box']
            srv.vm.network "private_network", ip: value['ip']
        srv.vm.hostname=key
        srv.vm.synced_folder ".", "/vagrant" , disabled:true
        srv.vm.synced_folder "ServersFS/"+key+"/", "/vagrant/ServersFS" , create: true
        srv.vm.synced_folder "./RaftFS", "/vagrant/RaftFS"
        srv.vm.provision :shell, path: "provision.sh"
        srv.vm.provider :virtualbox do |vb|
            vb.name = key
            vb.memory = value['ram']
            end
    end
  end
end

and this is servers.yaml file:

hal9000:
     box: hashicorp/precise32
     ram: 512
     ip: 172.17.8.101
     ftpPort: 8080
skynet:
     box: hashicorp/precise32
     ram: 512
     ip: 172.17.8.102
     ftpPort: 8081
jarvis:
     box: hashicorp/precise32
     ram: 512
     ip: 172.17.8.103
     ftpPort: 8083   
justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
  • What does `env | grep JAVA_HOME` show? – ydaetskcoR Mar 27 '15 at 18:03
  • Wow, didn't expect that: it's not set! Anyway, I tried to do execute manually `export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386` but then if I execute `java -version` it still return `java version "1.6.0_34"` – justHelloWorld Mar 28 '15 at 07:50
  • What OS and shell are you using on those boxes? – ydaetskcoR Mar 28 '15 at 08:29
  • I updated the question including the .yaml file in order to answer your question (which answer is precise32)...anyway I added the IMPORTANT UPDATE section too – justHelloWorld Mar 28 '15 at 08:34
  • Ok I set the JAVA_HOME successfully during the provisioning, but the version 6 is still returned with `java -version` ... do you think that I'm exporting `JAVA_HOME` in the wrong way? – justHelloWorld Mar 28 '15 at 09:57

2 Answers2

0

After installing new Java version, you must to inform your system where your Oracle Java JDK/JRE is located and with version must be used as default. This will tell the system that the new Oracle Java version is available for use.

For this you must use "update-alternatives", something like this:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_20/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_20/bin/javac" 1
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_20/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_20/bin/javac

Change paths to your openjdk-7-jdk files

Alexander R.
  • 1,756
  • 12
  • 19
0

I found out by myself the answer to my problem: I had simply to update the system's alternatives with these two commands:

sudo apt-get install icedtea-7-plugin
sudo update-java-alternatives -s java-1.7.0-openjdk-i386

The first one is necessary since this error would be thrown otherwise:

update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so

Now if I run java -version the correct version (7) is returned.

justHelloWorld
  • 6,478
  • 8
  • 58
  • 138