0

I have 3 installed versions of java (1.6,1.7,1.8) in my machine. Java alternatives has been configured to Java 1.8. So whenever i type java -version it is picking up from alternatives and showing java 1.8.

Here now i want to use other version of java (1.6 or 1.7), for that i have tried updating the .bashrc with other java paths. But still it is showing alternatives version (1.8)

enter image description here

Is there any way to override alternatives java from user level.

BruceWayne
  • 3,286
  • 4
  • 25
  • 35
  • What have you done _exactly_? Alternatives links `/usr/lib/jvm/java.../bin/java` to (via a number of indirections) to `/usr/bin/java` - what have you done to change this? – Boris the Spider Sep 23 '16 at 06:10
  • use alternatives to change the java version, all the java versions will be numbered, chose the version you want, thats it. – piyushj Sep 23 '16 at 06:10
  • Try the steps on this link it should do your job. http://ask.xmodulo.com/change-default-java-version-linux.html – mhasan Sep 23 '16 at 06:13
  • 1
    As your title speaks about `JAVA_HOME`: This variable is not used by the operating system for finding executables. It is the `PATH` variable, that you have to change if you want to use another Java version. – Seelenvirtuose Sep 23 '16 at 06:17
  • i have added screenshot of the scenario – BruceWayne Sep 23 '16 at 06:24

3 Answers3

0

Here is a blogpost explaining how to change jdk version in a *nix environment from terminal:

https://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/

mtyurt
  • 3,369
  • 6
  • 38
  • 57
0

There is no need to change your environment to switch Java version.

You can simply qualify the version you want to use. Alternatively, just make sure the version you want is first on the PATH, not last.

See my old answer for examples. It's for Windows, but it should work similarly for Linux.
  https://stackoverflow.com/a/32365879/5221149

Community
  • 1
  • 1
Andreas
  • 154,647
  • 11
  • 152
  • 247
  • It's very difficult to use your method. whenever i run java program by default it will pick from alternatives or .bashrc. – BruceWayne Sep 23 '16 at 06:47
0

Found the fix

I did like below

export PATH:new_java_path:$PATH. Now it started working for the current session.

BruceWayne
  • 3,286
  • 4
  • 25
  • 35