X
74 Rate this article:
No rating

(INTERNAL) Using Alternatives with multiple (Oracle) Java installations on Linux

Anonym

Linux steps to configuring Linux Alternatives utility to support one or more Oracle Java installations, to coexist with an already installed OpenJDK installation.

[ Note that IDL 8.3 includes Java 1.7 with the product installation. The examples below show Java 1.6 but the concept should also apply to installing Java 1.7. ]

1.) Download from Oracle the *.bin distribution/version of the jdk (or jre) needed to install.  Be sure to choose the correct bit version (32 or 64).

Here is the current JSE download page as of Dec 2013:

    http://www.oracle.com/technetwork/java/javase/downloads/index.html

================
Optionally, install Java from the downloaded RPM file

If no other Oracle Java versions are installed on the system, you could alternatively download and install from the RPM package distribution, e.g. (I think):

    sudo rpm --install /path/to/a_downloaded_java_rpm_pkg.rpm

Installing the RPM will create and install Java into the directory:  /usr/java

If you do install from the RPM, then skip to step 5 below.  Note that with this approach, the actual Java installation directory name may not be descriptive of the actual bit-version of the selected Java distribution.  (If so, I would hesitate renaming the main directory (as in step 4 below) to something different and more descriptive, although I have not experimented with doing this.)
================

2.) Copy the downloaded Java *.bin file to the directory location:  /usr/java/  (Create this directory if not already present)

3.) Unpack the *.bin using the "unzip" program.

4.) If needed, rename the unpacked main Java directory to something more reflective, for example, including the bit-version in the name.  For example, you might change a 64-bit distribution directory from:

    /usr/java/jdk1.6.0_21

-to-

    /usr/java/jdk1.6.0_21_x86_64

-or-

    /usr/java/jdk1.6.0_21_x86

5.) After installing the desired Java package into the /usr/java directory configure Alternatives to add the new Java version installation.

Below are example commands to issue to install and configure the default system version of Java on Linux.  Note that "/usr/bin/java" is a symlink to "/etc/alternatives/java" which itself is a configurable symlink to the actual selected version of the "java" file which is set with the call to "alternatives --config ...".  That is:

    alternatives --install /usr/bin/java java /path/to/actual/java [alternatives-list-number-to-set]

Note also that a call to "alternatives --config java" without root or sudo privileges is just a quick way to see the current system setting for "java" without intention to make any change.

Example commands to use, illustrated with installed file location "/usr/java/jdk1.6.0_21/bin/java" and addition into Alternatives java list as item #4:

    alternatives --config java
    sudo alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_21/bin/java 4
    sudo alternatives --config java
    alternatives --config java
    java -version

Here is an illustration of the above commands.

-bash-4.1$ alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
 + 2           /usr/java/jdk1.6.0_32/bin/java
   3           /usr/java/jdk1.6.0_32_i585/bin/java

Enter to keep the current selection[+], or type selection number: ^C
-bash-4.1$ sudo alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_21/bin/java 4
[sudo] password for tech_support:
-bash-4.1$ alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
 + 2           /usr/java/jdk1.6.0_32/bin/java
   3           /usr/java/jdk1.6.0_32_i585/bin/java
   4           /usr/java/jdk1.6.0_21/bin/java

Enter to keep the current selection[+], or type selection number: 4
-bash-4.1$ alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   2           /usr/java/jdk1.6.0_32/bin/java
   3           /usr/java/jdk1.6.0_32_i585/bin/java
 + 4           /usr/java/jdk1.6.0_21/bin/java

Enter to keep the current selection[+], or type selection number: ^C
-bash-4.1$

6.) If you downloaded the JDK rather than just the JRE, you may also wish to configure various versions of the Java compiler (javac) for use with Alternatives.  For example:

    alternatives --config javac
    sudo alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_21/bin/javac 3
    sudo alternatives --config javac
    alternatives --config javac
    javac -version

 

 

 [ Internal articles: Company Confidential, (not yet reviewed, internal reference only) ]