how to switch java version on Mac OS 10.8.4

how to switch java version on Mac OS 10.8.4

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).

How do I Update Java for my Mac?, Platform(s): Mac OS X If you choose Skip This Version, but later decide to check for an update, you can launch the Java Control Panel by clicking the Java icon  A Mac does not come with a default Java installed. If we need to do something with Java we will have to install java into the Mac OS. There are many ways to install Java in Mac OS. We might have multiple Java versions installed in Mac and we may need to switch versions. In this article we see ways to switch between different Java versions.


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.

How do I switch between Java 7 and Java 6 on OS X 10.8.2 , But now I don't seem to be able to find Java Preferences. I am running OS X 10.8.​2 (latest version). share. Switching Java Versions on MacOS [Snippets] Unsure of how to switch between multiple versions of Java on your Mac? Check out this quick tip to help you navigate those waters.


  1. Install an other Java version, that you need.

  2. I had to switch between 1.6_XX and 1.7_XX so wrote a litte script for that. It does its job pretty good. You have to replace some stuff but maybe it helps you:

    #!/bin/bash
    #v1.0.3
    #by Sapphire
    
    # /!\ Configuration /!\
    # vim ~/.bash_profile :
    # alias changej="sudo ~/Documents/changeJavaVers.sh"
    # sudo visudo -f /etc/sudoers :
    # #Custom privilege
    # user ALL=NOPASSWD: /Users/username/Documents/changeJavaVers.sh
    # change java dir's at (1) and (2)
    
    echo -e "\n***********************************************************"
    echo "*                EASY JAVA VERSION CHANGER                *"
    echo "***********************************************************"
    
    echo "Enter java version (6, 7, ..) or 'set' for settings"
    echo -n "Version: "
    read vers
    if [ "$vers" == "set" ]
    then
        echo "settings not implemented yet"
        #TODO open settings
        #set java home path, add java versions
        #current home: echo $JAVA_HOME
    elif (($vers == 6))
    then
        #(1)
        ln -fhsv /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
        export JAVA_HOME=`/usr/libexec/java_home -v 1.6+ -d32`
        echo -e "\n-----------------------------------------------------------"
        echo "                       JAVA VERSION"
        echo "-----------------------------------------------------------"
        java -version
        echo -e "\n-----------------------------------------------------------"
        echo "                        JAVA HOME"
        echo "-----------------------------------------------------------"
        echo $JAVA_HOME
        echo "***********************************************************"
    elif (($vers == 7))
    then
        #(2)
        ln -fhsv /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
        export JAVA_HOME=`/usr/libexec/java_home`
        echo -e "\n-----------------------------------------------------------"
        echo "                       JAVA VERSION"
        echo "-----------------------------------------------------------"
        java -version
        echo -e "\n-----------------------------------------------------------"
        echo "                        JAVA HOME"
        echo "-----------------------------------------------------------"
        echo $JAVA_HOME
        echo -e "\n***********************************************************"
    
    else
        echo -e "\ninvalid input - available java versions: 6, 7"
    fi
    

EDIT Got a newer version here. Works for me on OSX 10.9.3

#!/bin/bash
#v1.1.0
#last change: 12 June 2014
#by Sapphire

# /!\ Configuration /!\
# vim ~/.bash_profile :
# alias changej="sudo ~/Documents/changeJavaVers.sh"
# sudo visudo -f /etc/sudoers :
# #Custom privilege
# user ALL=NOPASSWD: /Users/username/Documents/changeJavaVers.sh
# change java directories (1), (2)

echo -e "\n***********************************************************"
echo "*                EASY JAVA VERSION CHANGER          v1.1.0 *"
echo "***********************************************************"

echo "Enter java version (6, 721, 745, 760) or 'set' for settings"
echo -n "Version: "
read vers
if [ "$vers" == "set" ]
then
    echo "settings not implemented yet"
    #TODO open settings
    #set java home path, add java versions
    #current home: echo $JAVA_HOME
elif (($vers == 6))
then
    #(1)
    ln -fhsv /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
elif (($vers == 721))
then
    #(1)
    ln -fhsv /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
elif (($vers == 745))
then
    #(1)
    ln -fhsv /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
elif (($vers == 760))
then
    #(1)
    ln -fhsv /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
else
    echo -e "\ninvalid input - available java versions: (6, 721, 745, 760)"
    exit
fi
#(2)
export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home'
echo -e "\n-----------------------------------------------------------"
echo "                       JAVA VERSION"
echo "-----------------------------------------------------------"
java -version
echo -e "\n-----------------------------------------------------------"
echo "                        JAVA HOME"
echo "-----------------------------------------------------------"
echo $JAVA_HOME
echo -e "\n***********************************************************"
exit

osx - how to switch java version on Mac OS 10.8.4, The cleanest way to manage multiple java versions on Mac is to use Homebrew. Homebrew. homebrew-cask to install the versions of java. jenv to manage the  Switching Java versions on Mac OS. uses the -v option to allow you to switch versions. Adding a couple of aliases to your .profile like this:


There is no need to download a whole new version. What you really want is this:

-target version
Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7).
The default for -target depends on the value of -source:

If -source is not specified, the value of -target is 1.7
If -source is 1.2, the value of -target is 1.4
If -source is 1.3, the value of -target is 1.4
If -source is 1.5, the value of -target is 1.7
If -source is 1.6, the value of -target is 1.7
For all other values of -source, the value of -target is the value of -source.  

from this source. -target and -source allow to control the target JVM and source code level. As the source says the value of target will default to the value you give source but you can control both if you want.

If this option can't provide a specific enough version for you, though I can't imagine why you would need such an exact version, then you'll just have to bite the bullet and download the right version yourself

Installation of the JDK and the JRE on macOS, If you want to install an earlier version, then you must first uninstall the existing version. Determining the Default JDK Version on macOS. When starting a Java  For example if you are using bash then you can set the command in the .bash_profile. Add the following lines at the end of the file. # Setting default JDK to version 1.8. export JAVA_HOME=`/usr/libexec/java_home -v 1.8`. To activate this configuration right away your can run source .bash_profile.


How can I switch between the two Java versions in Mountain Lion , I have two versions of Java installed with Mountain Lion: Apple's Java 6 Update 37 (Java for OS X 2012-006); Oracle's Java 7. The update from Apple removes  note: These solutions work for various versions of Java including Java 8 and the new Java 13, and for any other previous Java version covered by the listed version managers. This includes alternative JDK's from OpenJDK, Oracle, IBM, Azul, Amazon Correto, Graal and more.


Multiple Java versions support on OS X and JAVA_HOME location , Where a new JDK is usually installed? And final question : How can I choose which version should run by default by all applications? In Win. I set JAVA_HOME to  Based on disassembly, it turns out you can export JAVA_VERSION=1.7 to make java_home default to showing JKD7 instead of JDK8, but that breaks java_home -v 1.6 because java-home interprets it as an additional constraint and gives up due to mutually unsatisfiable constraints, then just goes with the default 1.8 even with the --failfast option. – andrewdotn Jan 25 '14 at 6:52


Download Java for OS X 2017-001, This package is exclusively intended for support of legacy software and installs the same deprecated version of Java 6 included in the 2015-001,  Note: At the time of writing, the OS in question is Mac OS X High Sierra 10.13.6. Mac OS X contains a rudimentary amount of developer tools underneath the shiny user interface. These packaged tools get outdated very fast, and developers are left scrambling to get the updated tools installed. Java, as a matter of fact, doesn’t come installed by default nowadays. My weapon of choice: Brew