0

I have 3 versions of java installed: adoptopenjdk-8.jdk, jdk-12.0.2.jdkand jdk1.0.0_221.jdk

when I set the JAVA_HOME variable to JAVA_HOME="/usr/libexec/java_home" then when I go to terminal type $JAVA_HOME, it gives the jdk-12.0.0.jdkversion.
How would I change it so it gives the adoptopenjdk-8.jdk version?

I tried to set it to:
export JAVA_HOME="/Library⁩/Java⁩/JavaVirtualMachines⁩/adoptopenjdk-8.jdk⁩/⁨Contents⁩/Home"
export PATH="$JAVA_HOME/bin:$PATH"

Expected to give adoptopenjdk-8.jdk java version.
But not sure how to change it to adoptopenjdk-8.jdk version rather than jdk-12.0.0.jdk

saintlyzero
  • 1,632
  • 2
  • 18
  • 26
TBM-Codes
  • 1
  • 2
  • change the symlink of `/etc/java` to your java version – Ashvin Sharma Oct 20 '19 at 10:11
  • how? do I do that? – TBM-Codes Oct 20 '19 at 10:14
  • 1
    For managing JDK versions (and not only) on Unix-like platforms I would recommend [SDKMAN!](https://sdkman.io/) – MartinBG Oct 20 '19 at 11:09
  • ok will see but not sure if that can change the java_home – TBM-Codes Oct 20 '19 at 11:17
  • JAVA_HOME is just an environment variable that some applications use. If you put the java bin on your path, then when you type java you should get the first version that appears first in your PATH value. Why do you say it is telling you jdk 12 then? – matt Oct 20 '19 at 11:48
  • It gives this when I type $JAVA_HOME if I set it to JAVA_HOME="/usr/libexec/java_home" in the bash_profiles. ------ /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home – TBM-Codes Oct 20 '19 at 12:08
  • What do you want to do? Either you can set JAVA_HOME to point to a specific version and then your program and any other that uses JAVA_HOME will use that version or you can change what /usr/libexec/java_home points to but then you will change the version for the whole computer so to speak. – Joakim Danielson Oct 20 '19 at 14:23
  • @TBM-Codes With this `sudo ln -s /bin/java /usr/bin/java` – Ashvin Sharma Oct 21 '19 at 04:34

0 Answers0