Friday 8 May 2015

Installing oracle jdk 8 on Centos 7.1

I want to install the java 8 jdk and to use that with groovy. That should be simple enough - but downloading the rpm and updating /etc/alternatives does not work. The problem is that the rpm installs java to a non-standard location and so groovy gives this error:

$ groovy -v
/bin/build-classpath: Could not find ../../jvm/java/lib Java extension for this JVM
/bin/build-classpath: error: Some specified jars were not found
Groovy Version: 1.8.9 JVM: 1.8.0_45 Vendor: Oracle Corporation OS: Linux

The solution is to install the tar.gz file version. First download it from Oracle.
Then, untar it and move the resulting directory to /usr/lib/jvm
tar xzf jdk-8u45-linux-x64.tar.gz
sudo mv jdk1.8.0_45 /usr/lib/jvm

Next, we set up the alternatives:

sudo alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_45/jre/bin/java 20000
sudo alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.8.0_45/bin/jar 20000
sudo alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_45/bin/javac 20000
sudo alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8.0_45/jre/bin/javaws 20000

Now, we can set the java version we want using update-alternatives:

sudo update-alternatives --config java
sudo update-alternatives --config jar
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Now groovy also expects to find the active java installation at /usr/jvm/java, so we need to link that to our active java. I don't really like this option as it breaks the alternatives structure we set-up earlier, but at the moment I don't have a better solution.

sudo mkdir /usr/jvm
sudo ln -s /usr/lib/jvm/jdk1.8.0_45 /usr/jvm/java

And now everything is groovy:

groovy -v Groovy Version: 1.8.9 JVM: 1.8.0_45 Vendor: Oracle Corporation OS: Linux