0

After installing two versions of java in rhel how do I point my program to one of those specific java file?

The java files that were installed were:

java-1.7.0-oracle-src-1.7.0.79-1jpp.1.el7_1.x86_64
java-1.8.0-oracle-javafx-1.8.0.45-1jpp.2.el7_1.x86_64
java-1.8.0-oracle-devel-1.8.0.45-1jpp.2.el7_1.x86_64
java-1.8.0-oracle-src-1.8.0.45-1jpp.2.el7_1.x86_64
java-1.7.0-oracle-javafx-1.7.0.79-1jpp.1.el7_1.x86_64
java-1.8.0-oracle-jdbc-1.8.0.45-1jpp.2.el7_1.x86_64
java-1.7.0-oracle-devel-1.7.0.79-1jpp.1.el7_1.x86_64
java-1.7.0-oracle-jdbc-1.7.0.79-1jpp.1.el7_1.x86_64
java-1.8.0-oracle-plugin-1.8.0.45-1jpp.2.el7_1.x86_64
java-1.7.0-oracle-1.7.0.79-1jpp.1.el7_1.x86_64
java-1.8.0-oracle-1.8.0.45-1jpp.2.el7_1.x86_64
java-1.7.0-oracle-plugin-1.7.0.79-1jpp.1.el7_1.x86_64
Xavier
  • 313
  • 2
  • 5
  • 18
  • Why not use `update-alternatives`? https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Web_Platform/5/html/Installation_Guide/sect-use_alternatives_to_set_default_JDK.html – Vitalii Elenhaupt May 28 '15 at 20:46

1 Answers1

1

Do you mean choosing what version of Java to use?

Some Linux distributions rely on update-alternatives tool to control what specific binary to use when multiple versions of it are installed. It works by setting symbolic links. For instance in my system, after installing openjdk, a symbolic link at:

/usr/bin/java

was created linked to the real java binary at:

/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

If update-alternatives is installed in your system, and the installation of Java updated its status correctly, you can choose the version of Java interactively by doing:

sudo update-alternatives --config java

Another approach: simply set JAVA_HOME and/or PATH environment variables right before you execute your command to switch between one or other Java version.

mauriciojost
  • 370
  • 1
  • 11
  • I read up on that, however the problem is i'll have programs running both java versions at the same time. My current work around is by using this command: { /opt/opennms/bin/runjava -S /usr/lib/jvm/java-1.8.0-oracle-1.8.0.45-1jpp.2.el7_1.x86_64/bin/java } as a way to link to the java binary file. – Xavier May 28 '15 at 21:49