Search code examples
javamacosjava-7dmg

How to install alt JDK on Mac without overriding current one


Mac here (Yosemite 10.10.5). I am using JDK 8 for all my projects, and recently just inherited an “older” Java 7-based project. I would simply like to download a Java 7 JDK from Oracle's archived JDKs, however it only seems to be available as a DMG (auto-installer).

I’m afraid that if I download this DMG it will auto-install it and make Java 7 my default installation. Whereas, I only want the unzipped JDK on my local file system, so that I can run my Java 7 app off of it (by specifying the full path to the JDK when I run the app locally).

Any ideas as to what my options are?


Solution

  • Most of the information about this can be found in Oracles notes on installation

    I believe what you are looking for specifically is under

    Determining the Default Version of the JDK:

    There can be multiple JDKs installed on a system, as many as you wish.

    When launching a Java application through the command line, the system uses the default JDK. It is possible for the version of the JRE to be different than the version of the JDK.

    You can determine which version of the JDK is the default by typing java -version in a Terminal window. If the installed version is 8u6, you will see a string that includes the text 1.8.0_06. For example:

    % java -version
    java version "1.8.0_06-ea"
    Java(TM) SE Runtime Environment (build 1.8.0_06-ea-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)
    

    To run a different version of Java, either specify the full path, or use the java_home tool:

    % /usr/libexec/java_home -v 1.8.0_06 --exec javac -version