Customer Login

Click Here

Free Trial

Click Here

Request a Demo

Click Here

Tuning Tips - Setting up Java on Linux

The challenge to setup java correctly on Linux

One of the challenges with setting up java on linux is making sure all of the dependent code is setup at the same time.

For example if java is set to jdk1.6.0_45 one also wants to make sure javac is also jdk1.6.0_45. If one swiches to jdk1.6.0_38 then both java and javac needs point to the correct version.

Using update-alternatives with the --slave switch makes this easy.

Steps to setup two versions of Java on Linux

1) Download and install java.
In this example, I have installed jdk1.6.0_38 in /usr/lib/jdk/jdk1.6.0_38 and jdk1.6.0_45 /usr/lib/jdk/jdk1.6.0_45

2) remove the old setting using
update-alternatives --remove

3) Install each version using
update-alternatives --install with --slave switch

4) Verify the install using
update-alternatives --display

Get Info on what is setup for java using update-alternatives

Use the following command to see what is install for java

update-alternatives --display java

This will display something like

update-alternatives --display java
java - status is manual.
link currently points to /usr/lib/jdk/jdk1.6.0_45/bin/java
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1420
slave keytool: /usr/lib/jvm/jre-1.4.2-gcj/bin/keytool
slave rmiregistry: /usr/lib/jvm/jre-1.4.2-gcj/bin/rmiregistry
slave jre_exports: /usr/lib/jvm-exports/jre-1.4.2-gcj
slave jre: /usr/lib/jvm/jre-1.4.2-gcj
/usr/lib/jdk/jdk1.6.0_38/bin/java - priority 10
slave keytool: (null)
slave rmiregistry: (null)
slave jre_exports: (null)
slave jre: (null)
/usr/lib/jdk/jdk1.6.0_45/bin/java - priority 11
slave keytool: (null)
slave rmiregistry: (null)
slave jre_exports: (null)
slave jre: (null)

Remove old version using update-alternatives -- remove

Use the following command to to remove old setting.

NOTE1: BE VERY CAREFUL running this command with the remove switch

NOTE2: This assumes the olc version was installed in /usr/lib/jdk/jdk1.6.0_45/bin/java

To see what is installed run:

alternatives --config java

Example:

update-alternatives --remove java /usr/lib/jdk/jdk1.6.0_45/bin/java

update-alternatives --remove java /usr/lib/jdk/jdk1.6.0_38/bin/java

Add java using update-alternativess

Use the following command to see what is install for java

Something like the following command installs jdk1.6.0_38 and jdk1.6.0_45 in two commands

update-alternatives --install /usr/bin/java java
/usr/lib/jdk/jdk1.6.0_38/bin/java 200 \
--slave /usr/bin/appletviewer appletviewer
/usr/lib/jdk/jdk1.6.0_38/bin/appletviewer \
--slave /usr/bin/apt apt /usr/lib/jdk/jdk1.6.0_38/bin/apt \
--slave /usr/bin/ControlPanel ControlPanel
/usr/lib/jdk/jdk1.6.0_38/bin/ControlPanel \
--slave /usr/bin/extcheck extcheck /usr/lib/jdk/jdk1.6.0_38/bin/extcheck \
--slave /usr/bin/HtmlConverter HtmlConverter
/usr/lib/jdk/jdk1.6.0_38/bin/HtmlConverter \
--slave /usr/bin/idlj idlj /usr/lib/jdk/jdk1.6.0_38/bin/idlj \
--slave /usr/bin/jar jar /usr/lib/jdk/jdk1.6.0_38/bin/jar \
--slave /usr/bin/jarsigner jarsigner /usr/lib/jdk/jdk1.6.0_38/bin/jarsigner \
--slave /usr/bin/javac javac /usr/lib/jdk/jdk1.6.0_38/bin/javac \
--slave /usr/bin/javadoc javadoc /usr/lib/jdk/jdk1.6.0_38/bin/javadoc \
--slave /usr/bin/javah javah /usr/lib/jdk/jdk1.6.0_38/bin/javah \
--slave /usr/bin/javap javap /usr/lib/jdk/jdk1.6.0_38/bin/javap \
--slave /usr/bin/javaws javaws /usr/lib/jdk/jdk1.6.0_38/bin/javaws \
--slave /usr/bin/jconsole jconsole /usr/lib/jdk/jdk1.6.0_38/bin/jconsole \
--slave /usr/bin/jcontrol jcontrol /usr/lib/jdk/jdk1.6.0_38/bin/jcontrol \
--slave /usr/bin/jdb jdb /usr/lib/jdk/jdk1.6.0_38/bin/jdb \
--slave /usr/bin/jhat jhat /usr/lib/jdk/jdk1.6.0_38/bin/jhat \
--slave /usr/bin/jinfo jinfo /usr/lib/jdk/jdk1.6.0_38/bin/jinfo \
--slave /usr/bin/jmap jmap /usr/lib/jdk/jdk1.6.0_38/bin/jmap \
--slave /usr/bin/jps jps /usr/lib/jdk/jdk1.6.0_38/bin/jps \
--slave /usr/bin/jrunscript jrunscript /usr/lib/jdk/jdk1.6.0_38/bin/jrunscript \
--slave /usr/bin/jsadebugd jsadebugd /usr/lib/jdk/jdk1.6.0_38/bin/jsadebugd \
--slave /usr/bin/jstack jstack /usr/lib/jdk/jdk1.6.0_38/bin/jstack \
--slave /usr/bin/jstat jstat /usr/lib/jdk/jdk1.6.0_38/bin/jstat \
--slave /usr/bin/jstatd jstatd /usr/lib/jdk/jdk1.6.0_38/bin/jstatd \
--slave /usr/bin/jvisualvm jvisualvm /usr/lib/jdk/jdk1.6.0_38/bin/jvisualvm \
--slave /usr/bin/keytool keytool /usr/lib/jdk/jdk1.6.0_38/bin/keytool \
--slave /usr/bin/native2ascii native2ascii
/usr/lib/jdk/jdk1.6.0_38/bin/native2ascii \
--slave /usr/bin/orbd orbd /usr/lib/jdk/jdk1.6.0_38/bin/orbd \
--slave /usr/bin/pack200 pack200 /usr/lib/jdk/jdk1.6.0_38/bin/pack200 \
--slave /usr/bin/policytool policytool /usr/lib/jdk/jdk1.6.0_38/bin/policytool \
--slave /usr/bin/rmic rmic /usr/lib/jdk/jdk1.6.0_38/bin/rmic \
--slave /usr/bin/rmid rmid /usr/lib/jdk/jdk1.6.0_38/bin/rmid \
--slave /usr/bin/rmiregistry rmiregistry
/usr/lib/jdk/jdk1.6.0_38/bin/rmiregistry \
--slave /usr/bin/schemagen schemagen /usr/lib/jdk/jdk1.6.0_38/bin/schemagen \
--slave /usr/bin/serialver serialver /usr/lib/jdk/jdk1.6.0_38/bin/serialver \
--slave /usr/bin/servertool servertool /usr/lib/jdk/jdk1.6.0_38/bin/servertool \
--slave /usr/bin/tnameserv tnameserv /usr/lib/jdk/jdk1.6.0_38/bin/tnameserv \
--slave /usr/bin/unpack200 unpack200 /usr/lib/jdk/jdk1.6.0_38/bin/unpack200 \
--slave /usr/bin/wsgen wsgen /usr/lib/jdk/jdk1.6.0_38/bin/wsgen \
--slave /usr/bin/wsimport wsimport /usr/lib/jdk/jdk1.6.0_38/bin/wsimport \
--slave /usr/bin/xjc xjc /usr/lib/jdk/jdk1.6.0_38/bin/xjc

update-alternatives --install /usr/bin/java java
/usr/lib/jdk/jdk1.6.0_45/bin/java 200 \
--slave /usr/bin/appletviewer appletviewer
/usr/lib/jdk/jdk1.6.0_45/bin/appletviewer \
--slave /usr/bin/apt apt /usr/lib/jdk/jdk1.6.0_45/bin/apt \
--slave /usr/bin/ControlPanel ControlPanel
/usr/lib/jdk/jdk1.6.0_45/bin/ControlPanel \
--slave /usr/bin/extcheck extcheck /usr/lib/jdk/jdk1.6.0_45/bin/extcheck \
--slave /usr/bin/HtmlConverter HtmlConverter
/usr/lib/jdk/jdk1.6.0_45/bin/HtmlConverter \
--slave /usr/bin/idlj idlj /usr/lib/jdk/jdk1.6.0_45/bin/idlj \
--slave /usr/bin/jar jar /usr/lib/jdk/jdk1.6.0_45/bin/jar \
--slave /usr/bin/jarsigner jarsigner /usr/lib/jdk/jdk1.6.0_45/bin/jarsigner \
--slave /usr/bin/javac javac /usr/lib/jdk/jdk1.6.0_45/bin/javac \
--slave /usr/bin/javadoc javadoc /usr/lib/jdk/jdk1.6.0_45/bin/javadoc \
--slave /usr/bin/javah javah /usr/lib/jdk/jdk1.6.0_45/bin/javah \
--slave /usr/bin/javap javap /usr/lib/jdk/jdk1.6.0_45/bin/javap \
--slave /usr/bin/javaws javaws /usr/lib/jdk/jdk1.6.0_45/bin/javaws \
--slave /usr/bin/jconsole jconsole /usr/lib/jdk/jdk1.6.0_45/bin/jconsole \
--slave /usr/bin/jcontrol jcontrol /usr/lib/jdk/jdk1.6.0_45/bin/jcontrol \
--slave /usr/bin/jdb jdb /usr/lib/jdk/jdk1.6.0_45/bin/jdb \
--slave /usr/bin/jhat jhat /usr/lib/jdk/jdk1.6.0_45/bin/jhat \
--slave /usr/bin/jinfo jinfo /usr/lib/jdk/jdk1.6.0_45/bin/jinfo \
--slave /usr/bin/jmap jmap /usr/lib/jdk/jdk1.6.0_45/bin/jmap \
--slave /usr/bin/jps jps /usr/lib/jdk/jdk1.6.0_45/bin/jps \
--slave /usr/bin/jrunscript jrunscript /usr/lib/jdk/jdk1.6.0_45/bin/jrunscript \
--slave /usr/bin/jsadebugd jsadebugd /usr/lib/jdk/jdk1.6.0_45/bin/jsadebugd \
--slave /usr/bin/jstack jstack /usr/lib/jdk/jdk1.6.0_45/bin/jstack \
--slave /usr/bin/jstat jstat /usr/lib/jdk/jdk1.6.0_45/bin/jstat \
--slave /usr/bin/jstatd jstatd /usr/lib/jdk/jdk1.6.0_45/bin/jstatd \
--slave /usr/bin/jvisualvm jvisualvm /usr/lib/jdk/jdk1.6.0_45/bin/jvisualvm \
--slave /usr/bin/keytool keytool /usr/lib/jdk/jdk1.6.0_45/bin/keytool \
--slave /usr/bin/native2ascii native2ascii /usr/lib/jdk/jdk1.6.0_45/bin/native2ascii \
--slave /usr/bin/orbd orbd /usr/lib/jdk/jdk1.6.0_45/bin/orbd \
--slave /usr/bin/pack200 pack200 /usr/lib/jdk/jdk1.6.0_45/bin/pack200 \
--slave /usr/bin/policytool policytool /usr/lib/jdk/jdk1.6.0_45/bin/policytool \
--slave /usr/bin/rmic rmic /usr/lib/jdk/jdk1.6.0_45/bin/rmic \
--slave /usr/bin/rmid rmid /usr/lib/jdk/jdk1.6.0_45/bin/rmid \
--slave /usr/bin/rmiregistry rmiregistry /usr/lib/jdk/jdk1.6.0_45/bin/rmiregistry \
--slave /usr/bin/schemagen schemagen /usr/lib/jdk/jdk1.6.0_45/bin/schemagen \
--slave /usr/bin/serialver serialver /usr/lib/jdk/jdk1.6.0_45/bin/serialver \
--slave /usr/bin/servertool servertool /usr/lib/jdk/jdk1.6.0_45/bin/servertool \
--slave /usr/bin/tnameserv tnameserv /usr/lib/jdk/jdk1.6.0_45/bin/tnameserv \
--slave /usr/bin/unpack200 unpack200 /usr/lib/jdk/jdk1.6.0_45/bin/unpack200 \
--slave /usr/bin/wsgen wsgen /usr/lib/jdk/jdk1.6.0_45/bin/wsgen \
--slave /usr/bin/wsimport wsimport /usr/lib/jdk/jdk1.6.0_45/bin/wsimport \
--slave /usr/bin/xjc xjc /usr/lib/jdk/jdk1.6.0_45/bin/xjc

Verify the install Using update-alternatives --display java

Use the following command to see what is install for java

update-alternatives --display java

This will display something like

update-alternatives --display java
java - status is manual.
link currently points to /usr/lib/jdk/jdk1.6.0_45/bin/java
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1420
slave keytool: /usr/lib/jvm/jre-1.4.2-gcj/bin/keytool
slave rmiregistry: /usr/lib/jvm/jre-1.4.2-gcj/bin/rmiregistry
slave jre_exports: /usr/lib/jvm-exports/jre-1.4.2-gcj
slave jre: /usr/lib/jvm/jre-1.4.2-gcj
/usr/lib/jdk/jdk1.6.0_38/bin/java - priority 10
slave keytool: (null)
slave rmiregistry: (null)
slave jre_exports: (null)
slave jre: (null)
/usr/lib/jdk/jdk1.6.0_45/bin/java - priority 11
slave keytool: (null)
slave rmiregistry: (null)
slave jre_exports: (null)
slave jre: (null)

Verify the install Using update-alternatives --display java

Use the following command to see what is install for java

update-alternatives --display java

This will display something like

update-alternatives --display java
java - status is manual.
link currently points to /usr/lib/jdk/jdk1.6.0_45/bin/java
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1420
slave ControlPanel: (null)
slave HtmlConverter: (null)
slave appletviewer: (null)
slave apt: (null)
slave extcheck: (null)
slave idlj: (null)
slave jar: (null)
slave jarsigner: (null)
slave javac: (null)
slave javadoc: (null)
slave javah: (null)
slave javap: (null)
slave javaws: (null)
slave jconsole: (null)
slave jcontrol: (null)
slave jdb: (null)
slave jhat: (null)
slave jinfo: (null)
slave jmap: (null)
slave jps: (null)
slave jrunscript: (null)
slave jsadebugd: (null)
slave jstack: (null)
slave jstat: (null)
slave jstatd: (null)
slave jvisualvm: (null)
slave keytool: /usr/lib/jvm/jre-1.4.2-gcj/bin/keytool
slave native2ascii: (null)
slave orbd: (null)
slave pack200: (null)
slave policytool: (null)
slave rmic: (null)
slave rmid: (null)
slave rmiregistry: /usr/lib/jvm/jre-1.4.2-gcj/bin/rmiregistry
slave schemagen: (null)
slave serialver: (null)
slave servertool: (null)
slave tnameserv: (null)
slave unpack200: (null)
slave wsgen: (null)
slave wsimport: (null)
slave xjc: (null)
slave jre_exports: /usr/lib/jvm-exports/jre-1.4.2-gcj
slave jre: /usr/lib/jvm/jre-1.4.2-gcj
/usr/lib/jdk/jdk1.6.0_45/bin/java - priority 200
slave ControlPanel: /usr/lib/jdk/jdk1.6.0_45/bin/ControlPanel
slave HtmlConverter: /usr/lib/jdk/jdk1.6.0_45/bin/HtmlConverter
slave appletviewer: /usr/lib/jdk/jdk1.6.0_45/bin/appletviewer
slave apt: /usr/lib/jdk/jdk1.6.0_45/bin/apt
slave extcheck: /usr/lib/jdk/jdk1.6.0_45/bin/extcheck
slave idlj: /usr/lib/jdk/jdk1.6.0_45/bin/idlj
slave jar: /usr/lib/jdk/jdk1.6.0_45/bin/jar
slave jarsigner: /usr/lib/jdk/jdk1.6.0_45/bin/jarsigner
slave javac: /usr/lib/jdk/jdk1.6.0_45/bin/javac
slave javadoc: /usr/lib/jdk/jdk1.6.0_45/bin/javadoc
slave javah: /usr/lib/jdk/jdk1.6.0_45/bin/javah
slave javap: /usr/lib/jdk/jdk1.6.0_45/bin/javap
slave javaws: /usr/lib/jdk/jdk1.6.0_45/bin/javaws
slave jconsole: /usr/lib/jdk/jdk1.6.0_45/bin/jconsole
slave jcontrol: /usr/lib/jdk/jdk1.6.0_45/bin/jcontrol
slave jdb: /usr/lib/jdk/jdk1.6.0_45/bin/jdb
slave jhat: /usr/lib/jdk/jdk1.6.0_45/bin/jhat
slave jinfo: /usr/lib/jdk/jdk1.6.0_45/bin/jinfo
slave jmap: /usr/lib/jdk/jdk1.6.0_45/bin/jmap
slave jps: /usr/lib/jdk/jdk1.6.0_45/bin/jps
slave jrunscript: /usr/lib/jdk/jdk1.6.0_45/bin/jrunscript
slave jsadebugd: /usr/lib/jdk/jdk1.6.0_45/bin/jsadebugd
slave jstack: /usr/lib/jdk/jdk1.6.0_45/bin/jstack
slave jstat: /usr/lib/jdk/jdk1.6.0_45/bin/jstat
slave jstatd: /usr/lib/jdk/jdk1.6.0_45/bin/jstatd
slave jvisualvm: /usr/lib/jdk/jdk1.6.0_45/bin/jvisualvm
slave keytool: /usr/lib/jdk/jdk1.6.0_45/bin/keytool
slave native2ascii: /usr/lib/jdk/jdk1.6.0_45/bin/native2ascii
slave orbd: /usr/lib/jdk/jdk1.6.0_45/bin/orbd
slave pack200: /usr/lib/jdk/jdk1.6.0_45/bin/pack200
slave policytool: /usr/lib/jdk/jdk1.6.0_45/bin/policytool
slave rmic: /usr/lib/jdk/jdk1.6.0_45/bin/rmic
slave rmid: /usr/lib/jdk/jdk1.6.0_45/bin/rmid
slave rmiregistry: /usr/lib/jdk/jdk1.6.0_45/bin/rmiregistry
slave schemagen: /usr/lib/jdk/jdk1.6.0_45/bin/schemagen
slave serialver: /usr/lib/jdk/jdk1.6.0_45/bin/serialver
slave servertool: /usr/lib/jdk/jdk1.6.0_45/bin/servertool
slave tnameserv: /usr/lib/jdk/jdk1.6.0_45/bin/tnameserv
slave unpack200: /usr/lib/jdk/jdk1.6.0_45/bin/unpack200
slave wsgen: /usr/lib/jdk/jdk1.6.0_45/bin/wsgen
slave wsimport: /usr/lib/jdk/jdk1.6.0_45/bin/wsimport
slave xjc: /usr/lib/jdk/jdk1.6.0_45/bin/xjc
slave jre_exports: (null)
slave jre: (null)
/usr/lib/jdk/jdk1.6.0_38/bin/java - priority 200
slave ControlPanel: /usr/lib/jdk/jdk1.6.0_38/bin/ControlPanel
slave HtmlConverter: /usr/lib/jdk/jdk1.6.0_38/bin/HtmlConverter
slave appletviewer: /usr/lib/jdk/jdk1.6.0_38/bin/appletviewer
slave apt: /usr/lib/jdk/jdk1.6.0_38/bin/apt
slave extcheck: /usr/lib/jdk/jdk1.6.0_38/bin/extcheck
slave idlj: /usr/lib/jdk/jdk1.6.0_38/bin/idlj
slave jar: /usr/lib/jdk/jdk1.6.0_38/bin/jar
slave jarsigner: /usr/lib/jdk/jdk1.6.0_38/bin/jarsigner
slave javac: /usr/lib/jdk/jdk1.6.0_38/bin/javac
slave javadoc: /usr/lib/jdk/jdk1.6.0_38/bin/javadoc
slave javah: /usr/lib/jdk/jdk1.6.0_38/bin/javah
slave javap: /usr/lib/jdk/jdk1.6.0_38/bin/javap
slave javaws: /usr/lib/jdk/jdk1.6.0_38/bin/javaws
slave jconsole: /usr/lib/jdk/jdk1.6.0_38/bin/jconsole
slave jcontrol: /usr/lib/jdk/jdk1.6.0_38/bin/jcontrol
slave jdb: /usr/lib/jdk/jdk1.6.0_38/bin/jdb
slave jhat: /usr/lib/jdk/jdk1.6.0_38/bin/jhat
slave jinfo: /usr/lib/jdk/jdk1.6.0_38/bin/jinfo
slave jmap: /usr/lib/jdk/jdk1.6.0_38/bin/jmap
slave jps: /usr/lib/jdk/jdk1.6.0_38/bin/jps
slave jrunscript: /usr/lib/jdk/jdk1.6.0_38/bin/jrunscript
slave jsadebugd: /usr/lib/jdk/jdk1.6.0_38/bin/jsadebugd
slave jstack: /usr/lib/jdk/jdk1.6.0_38/bin/jstack
slave jstat: /usr/lib/jdk/jdk1.6.0_38/bin/jstat
slave jstatd: /usr/lib/jdk/jdk1.6.0_38/bin/jstatd
slave jvisualvm: /usr/lib/jdk/jdk1.6.0_38/bin/jvisualvm
slave keytool: /usr/lib/jdk/jdk1.6.0_38/bin/keytool
slave native2ascii: /usr/lib/jdk/jdk1.6.0_38/bin/native2ascii
slave orbd: /usr/lib/jdk/jdk1.6.0_38/bin/orbd
slave pack200: /usr/lib/jdk/jdk1.6.0_38/bin/pack200
slave policytool: /usr/lib/jdk/jdk1.6.0_38/bin/policytool
slave rmic: /usr/lib/jdk/jdk1.6.0_38/bin/rmic
slave rmid: /usr/lib/jdk/jdk1.6.0_38/bin/rmid
slave rmiregistry: /usr/lib/jdk/jdk1.6.0_38/bin/rmiregistry
slave schemagen: /usr/lib/jdk/jdk1.6.0_38/bin/schemagen
slave serialver: /usr/lib/jdk/jdk1.6.0_38/bin/serialver
slave servertool: /usr/lib/jdk/jdk1.6.0_38/bin/servertool
slave tnameserv: /usr/lib/jdk/jdk1.6.0_38/bin/tnameserv
slave unpack200: /usr/lib/jdk/jdk1.6.0_38/bin/unpack200
slave wsgen: /usr/lib/jdk/jdk1.6.0_38/bin/wsgen
slave wsimport: /usr/lib/jdk/jdk1.6.0_38/bin/wsimport
slave xjc: /usr/lib/jdk/jdk1.6.0_38/bin/xjc
slave jre_exports: (null)
slave jre: (null)
Current `best' version is /usr/lib/jvm/jre-1.4.2-gcj/bin/java.

We offer the Tuning Ace Nucleus part of the Tuning Ace Performance Tuning Suite. For more information please contact us here.

Please send us comments here TuningTipComments@TuningAce.com

This document is provided for information purposes only and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document.