I need to switch the Java version on my Mac OS X 10.8.4
but am not sure how, the version I have right now is 1.6.0_51
but i want to switch to 1.6.0_45
:
$java -version java version "1.6.0_51" Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509) Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode) /usr/libexec/java_home -v 1.6.0_43 Unable to find any JVMs matching version "1.6.0_43". /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
I assume there is no such a version as 1.6.0_43
on my mac? how can install it and then switch to it? thanks!
To see which versions you have installed use:
/usr/libexec/java_home -V
For example shows this for me:
15:04 $ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
10.0.1, x86_64: "Java SE 10.0.1" /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
1.7.0_80, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
Then simply in your ~/.bashrc
or ~/.bash_profile
:
$ export JAVA_HOME=$(/usr/libexec/java_home -v 1.7.0_80)
As for getting version 1.6 (or nearly any prev version) I think that as of this date (Nov 2018) you will be out of luck. I can get to https://jdk.java.net/8/ but any earlier version is a 404 (11 is the latest). I'm sure you could search a bit more though as I understand it, once they (Oracle) have discontinued a version, they no longer maintain it since it could be a security risk.
Once you have DL a Mac .dmg, I'm sure it installs in the correct location and will be visible with java_home
.
There is information at https://stackoverflow.com/a/47699905/1019307 that discusses using homebrew
to install Java and it mentions Java6 (the post is dated Dec 2017).
As the description says on this website: "...it’s really a pain to switch between this Java version by shell..." so this person made a tool to do the switching. Since I don't know your reasoning (if you really have to do it via the command line) it may not be overly useful but a quick google search revealed this downloadable tool from their website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With