We use to run java OpenJDK 6 on our servers, but the new version OpenJDK 7 is more secure and some of our customers have start requesting, so here are the instructions for installing and setting the correct variables.

For the previous post on installing OpenJDK 6 please see red5 installation.

Please note that it is possible to have on the same server both version OpenJDK 6 and OpenJDK 7.

First command, let us install OpenJDK:

# yum install java-1.7.0-openjdk-devel

Linux Centos servers include a utility called alternatives, which lets you change the default version for applications which allow multiple versions to be installed. OpenJDK is one such application.

  • The alternatives command is not installed by default, but may already be installed on your system. If not, install the alternatives package by running the following command:
    # yum install alternatives
  • Issue the following command:
    # /usr/sbin/alternatives --config java

the output could be something like:

# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
2           /usr/lib/jvm/jre-1.7.0-openjdk/bin/java

Enter to keep the current selection[+], or type selection number: 2

if you type 2 the you selecting the OpenJDK 7.

and you can confirm by entering the command:

# java -version

the output should be something like:

[root@live ~]# java -version
java version “1.7.0_51”
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-i386 u51-b02)
OpenJDK Client VM (build 24.45-b08, mixed mode, sharing)

Setup Environment Variables

Most of java based application’s uses environment variables to work. Use following commands to setup it.
# export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk/bin/java

# export CLASSPATH=.:$JAVA_HOME/lib/classes.zip

Also export these variables in /etc/bashrc to become available for every user login or for any terminal opens.
# echo export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk/bin/java >> /etc/bashrc

# echo export CLASSPATH=.:$JAVA_HOME/lib/classes.zip >> /etc/bashrc

Check if the variables are correct:

# echo $JAVA_HOME

output should be:

[root@live ~]# echo $JAVA_HOME
/usr/lib/jvm/jre-1.7.0-openjdk/bin/java
[root@live ~]#

 

That’s it.