How can I completely remove Apple's Java 6 and make Oracle's Java 7 default for everything?

I would like to completely remove Apple's Java 6 and make Oracle's Java 7 default for every program. For example, with Eclipse I had to fiddle with eclipse.ini to specify JAVA_HOME for Java 7, and the same for TunnelBear. No luck for Aptana, though (it still wants Apple's Java) Is there a way to make Oracle's Java default in terms of PATH?


Solution 1:

Download and install the latest Java Development Kit (JDK) from Oracle, which will place it in /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk (or whatever the latest version is). Now, start Terminal.app, and enter the following commands:

  1. cd /System/Library/Java/JavaVirtualMachines (change to the proper directory)

  2. sudo mv 1.6.0.jdk backup.1.6.0.jdk (keep the old JDK around, just in case - you will need to have an administrator password to do this)

  3. sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk 1.6.0.jdk (link your new JDK installation to where applications expect the old one to be)

Keep in mind that with any further jdk updates, you'll need to update the symlink to the new directory:

sudo rm /System/Library/Java/JavaVirtualMachines/1.6.0.jdk && sudo ln -s /Library/Java/JavaVirtualMachines/new_jdk_version /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

Solution 2:

These instructions worked well for me on OS X Mavericks.

  • Remove Apple's JVMs

    $ sudo rm -rf /System/Library/Java/JavaVirtualMachines/
    
  • Remove installer records

    $ sudo rm /private/var/db/receipts/com.apple.pkg.JavaForMacOSX*
    
  • Remove installer receipts (delete the <dict>...</dict> entries that reference com.apple and java)

    $ sudo emacs /Library/Receipts/InstallHistory.plist
    
  • Set the symlinks for Java 7

    $ sudo rm /usr/bin/java
    $ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/bin/java /usr/bin/java
    
  • Optionally symlink JAVA_HOME

    sudo rm /Library/Java/Home
    sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home /Library/Java/Home