Search code examples
javamacosdirectory-structure

Want to keep JDKs together in one place on a macbook


On a Macbook with Yosemite, I have Java JDKs 1.6 and 1.8 in the following directories respectively:

/System/Library/Java/JavaVirtualMachines/
/Library/Java/JavaVirtualMachines/

I'm also pretty sure I have 1.7 somewhere but can't find it right now (if not I'm probably going to get it). Anyhow I was thinking et'd be a good idea to keep them all together, so where do you think I should put them? Why? Does it matter as long as the software I'm using (e.g. Eclipse) knows where they are?

Thanks, Niall


Solution

  • up to version 6 Java was provided by Apple and was installed in /System/Library/Java/JavaVirtualMachines/. Since version 7 Java is provided by Oracle and is installed in /Library/Java/JavaVirtualMachines/ when using the .dmg installer.

    I would advise against moving the old installation of version 6 to a different places, there used to be a couple of symlinks pointing to that installation.

    From 7 on, they reside side by side in the given directory, and so are in one place. For example this is the content of my /Library/Java/JavaVirtualMachines directory:

    drwxr-xr-x  3 root  wheel  102  7 Aug 10:21 jdk1.7.0_67.jdk
    drwxr-xr-x  3 root  wheel  102 15 Okt 10:46 jdk1.7.0_71.jdk
    drwxr-xr-x  3 root  wheel  102 28 Apr  2014 jdk1.8.0_05.jdk
    drwxr-xr-x  3 root  wheel  102 16 Jul 10:32 jdk1.8.0_11.jdk
    drwxr-xr-x  3 root  wheel  102  4 Sep 12:34 jdk1.8.0_20.jdk
    drwxr-xr-x  3 root  wheel  102 15 Okt 10:47 jdk1.8.0_25.jdk
    

    If you need to point your JAVA_HOME environment variable automatically to the actual version, you can put the following command in your .bash_profile:

    export JAVA_HOME=$(/usr/libexec/java_home)
    

    In your IDE, Eclipse or IDEA, set the path to the installation directory to the needed JDK by defining a JDK or JRE pointing to the directory with the needed version. I myself didn't even reinstall Java 6 after updating to yosemite, so my installations are all in one place.