Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Java installations in Mac OS X Mavericks

I downloaded JDK for Mac OS X 10.9.1 from Oracle, but I had to install another Java from Apple site once more, as I couldn't launch eclipse with it.

These are two pages that I referred.

  • Installing Java on OS X 10.9 (Mavericks)
  • http://support.apple.com/kb/DL1572?viewlocale=en_US

Now I have three java binaries installed in my computer.

Installation A

/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Installation B

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Installation C

/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

I found that I can easily remove Installation C, however I'm not sure if this is OK.

When I invoked java from command line, it points to Installation A.

java -version
java version "1.7.0_51"

ls -alF `which java`
lrwxr-xr-x  1 root  wheel  74 Jan 15 09:12 /usr/bin/java@ -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
  • Is there any way to use just one JDK 1.7 for Mavericks by removing two of them safely?

EDIT

After some setup and test, I have only one Java (1.6) installed. I have Installation B, and now Installation C is linked to Installation A.

For using eclipse, I had to make Compiler Compliance level to 1.6 to use it (from the help java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0).

enter image description here

EDIT2

This seems to what happened.

  1. Installation of Apple Java

    • Installation A
    • Installation B is a symbolic link to A
  2. Installation of Oracle Java

    • Installation C
    • Changed the Installation B that
      1. Created a /System/Library/Frameworks/JavaVM.framework/Versions/A
      2. Copied files from Installation C (not symbolic link)
      3. Make a symlink Current to Versions/A

I tried to install Oracle Java only by removing Apple Java, but I got installation error, so I guess Apple Java is needed to install Oracle Java.

like image 842
prosseek Avatar asked Jan 15 '14 20:01

prosseek


People also ask

Can I have multiple Java versions installed on Mac?

The cleanest way to manage multiple java versions on Mac is to use Homebrew . And within Homebrew , use: homebrew-cask to install the versions of java. jenv to manage the installed versions of java.

Can you have multiple Java versions installed?

It is very possible to run multiple versions of Java on the same machine so you can run your existing applications and Ignition at the same time.


2 Answers

Specify the JVM for Eclipse

You can specify JDK version for usage with Eclipse in eclipse.ini. This will resolve problem with starting Eclipse.

-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java

Warning: Add this configuration before -vmargs.

Master your Java Environnement with jenv

It is much easier to maintain multiple JDK versions with jenv.

jenv is for a equivalent of rbenv, but for Java environnement. It allow to easily switch between several JDKs installations (already presents), and configure which one to use per project.

Eclipse JDK

  • Setting JDK in Eclipse
like image 84
MariuszS Avatar answered Oct 05 '22 12:10

MariuszS


It seems like that the oracle JDK can be just removed. For eclipse, I could add Installation A as a default JRE from Java Build Path -> JRE System Library -> Installed JRES -> Add ...

enter image description here

like image 40
prosseek Avatar answered Oct 05 '22 11:10

prosseek