1

I have a server running rhel5 and jre 1.6. All my apps are running perfectly for now. But I want to install java 1.7 but keeping java 1.6 as the default so my running apps want be affected. If I want to install java 1.7 from a rpm how can I do this, and how can I run a my new app with the new version of java without changing default java version

ivcode
  • 1,062
  • 1
  • 9
  • 13

3 Answers3

3

Install the java versions you want, running applications should not be affected despite the default java version being changed. Then run the alternatives utility to pick your default java version:

alternatives --config java
alternatives --config javac

Verify your setup with

java -version
javac -version

If you're unsure, try this on a non-production host first.

Edit: To force tomcat to use a specific java version, no matter what the default, place a setenv.sh in tomcat's bin directory containing

JAVA_HOME=/path/to/jdk

Source: https://stackoverflow.com/questions/1698913/how-to-set-java-home-in-tomcat-config

fuero
  • 9,591
  • 1
  • 35
  • 40
  • In addition to alternatives --config java, for jdk you must run alternatives --config javac to choose which jdk environment you want to run your application in. – Zeeshan Jul 30 '14 at 00:14
  • Problem is, even though my running apps use older java version I want to run only tomcat from a newer java version. How can I achieve this? – ivcode Aug 11 '14 at 06:32
  • 1
    @ivcode I've updated my answer. – fuero Aug 11 '14 at 08:46
1

First of all install Java 7/8 using:

sudo apt-get install openjdk-7-jdk

Then you need to update alternatives using:

sudo update-alternatives --config java

You will see:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

Chose one that you need and type:

java -version

Then you can run your app on Java 7 and after that rollback it to 6 version.

0

first you need to make sure that your java apps are running thier java/javac from an absolute path. now the default java is the java you have when you execute:

# java -version

every java app you want to run must specify the absolute path according to your needs. to change the default execute:

# which java

and find out where is your default java bin is located and change the link to your designated jdk