User Tools

Site Tools


linux:install_java

This is an old revision of the document!


Install Java

This page shows how to install and update Oracle JDK on a CentOS 6 64bit server.

Prerequisites

You must have a CentOS machine already set up in accordance with the the “Install CentOS 6” guide.

If you are installing Oracle Java on a Tomcat machine, uninstall all CentOS supplied Java first by running the following command as root.

yum -y remove *java-1.*

Install Java

Start out by installing a prerequisite.

yum -y install ld-linux.so.2

Download the Java Linux 64bit *.tar.gz file and get it onto the server. For the purpose of this guide, it is assumed that the file is called jdk-8u45-linux-x64.tar.gz and that you have put it in the /tmp directory on the server.

For the record, the following are links to the various flavours of Java

Login as root and run the following commands. Change the value of FILENAME and DIR as appropriate.

MAINVERSION=8
SUBVERSION=45
FILENAME=jdk-${MAINVERSION}u${SUBVERSION}-linux-x64.tar.gz
DIR=jdk1.${MAINVERSION}.0_${SUBVERSION}
mkdir -p /opt/java
mv /tmp/$FILENAME /opt/java
cd /opt/java
tar zxf $FILENAME
rm -f $FILENAME
ln -s $DIR default
alternatives --install /usr/bin/java java /opt/java/default/jre/bin/java 2000

Test it

java -version
echo "export JAVA_HOME=/opt/java/default; export JAVA_HOME" >> /etc/profile

A note on the 'alternatives' command. This allows us to specify each install of Java and use the 'alternatives –config java' command to select which version of Java we use. We could use this by replacing 'default' with the actual Java install path when issuing the 'alternatives –install …' command. However, we choose instead to specify /opt/java/default/jre/bin/java as the Java path and then manually point the /opt/java/default symlink at the version of Java we wish to use.

Upgrade Java

For the purpose of this guide, it is assumed that the file is called jdk-7u22-linux-x64.tar.gz and that you have put it in the /tmp directory on the server. It is also assumed that you have already installed a version of Oracle Java using the steps given above.

Login as root and run the following commands. Change the value of FILENAME and DIR as appropriate.

MAINVERSION=8
SUBVERSION=45
FILENAME=jdk-${MAINVERSION}u${SUBVERSION}-linux-x64.tar.gz
DIR=jdk1.${MAINVERSION}.0_${SUBVERSION}
mv /tmp/$FILENAME /opt/java
cd /opt/java
tar zxf $FILENAME
rm -f $FILENAME
rm -f latest
ln -s $DIR latest

Test it

java -version

Downgrade Java

In the event that a Java upgrade has caused issues with the applications using it, you may need to revert to using and older version of Java. For the purpose of this guide, it is assumed that you will only downgrade to a version of Oracle Java already installed using one of methods described above.

cd /opt/java
DIR=jdk1.8.0_40
rm -f latest
ln -s $DIR latest

Test it

java -version

Get Firefox Java Plugin Working

To get Java working in the Firefox browser on 64bit CentOS, you need to install Oracle's Java then run the following as root

ln -s /opt/java/default/jre/lib/amd64/libnpjp2.so /usr/lib64/mozilla/plugins/

Then restart Firefox

Set Java Security

In CentOS, to set Oracle Java Security Settings, launch the control panel with the following command and then, in the security tab, set the level to medium.

/opt/java/default/bin/ControlPanel
linux/install_java.1590330965.txt.gz · Last modified: (external edit)