303

So I installed the beta of JDK 8 a while ago to look at some of the examples. I thought for sure by now, it's easy to change between versions.

Doing some Play development with IntelliJ. For some reason, IntelliJ is compiling with 8 even though:

  • I have the compiler set in Preferences to use 1.6
  • Supposedly it's using SBT through external build, but sbt from the command line works
  • JAVA_HOME is pointing to JDK 6.

If I go to the Java Preferences page, it does show 8 installed, but there is no option to uninstall it and it doesn't see any of the other versions.

When I do which java, it tells me /usr/bin/java and I do /usr/bin/java -version and it returns 1.6.

Note: with a little fiddling, you can use IntelliJ and JDK7, see here.

Community
  • 1
  • 1
Rob
  • 11,446
  • 7
  • 39
  • 57
  • 2
    Why do you want to use JDK 6? It has been EOL'd, see http://www.oracle.com/technetwork/java/eol-135779.html. If you don't want a beta version (JDK 8), you should move to JDK 7. – kmorris Sep 26 '13 at 23:53
  • 1
    JDK7 on Mac is still a mess. Have had a lot of issues with it. But I would take 7 at this point. (Though, in case you didn't know, JetBrains is still saying they don't support it on mac..!) – Rob Sep 26 '13 at 23:55
  • I hadn't heard that JetBrains won't support it... and Oracle won't support JDK6 any more. I did get jdk 7 to work, I'll post an answer. – kmorris Sep 27 '13 at 00:32
  • 3
    Also consider installing jdk as a homebrew cask - (un)installing/upgrading then is a simple brew command. – Agoston Horvath Sep 18 '14 at 12:32
  • 2
    Seems like using `Homebrew`& `Jenv` to manage the installed `Java` version is the way to go. see http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html – Adriano Mar 22 '15 at 12:24
  • 1
    I found it useful to reference homebrew-cask java formulas on how they uninstall jdk. [jdk9](https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb) & [jdk8](https://github.com/caskroom/homebrew-versions/blob/master/Casks/java8.rb). – Bruce Sun Sep 30 '17 at 06:30
  • For anyone else discovering a similar issue, my jenkins installation kept using jdk 11 despite `java -version` saying it was using 8, despite jenkins configured to use jdk 8, and despite java_home pointing to jdk 8. I uninstalled all java and just installed 8... then it worked. – Sam Jun 17 '19 at 20:35
  • BTW you don't have to uninstall any JDK from macOS. You can set your JAVA_HOME environment variable like this `export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)`. – Pankaj Jangid Oct 16 '20 at 13:54

14 Answers14

789

I was able to unistall jdk 8 in mavericks successfully doing the following steps:

Run this command to just remove the JDK

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk<version>.jdk

Run these commands if you want to remove plugins

sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
sudo rm -rf /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper
sudo rm -rf /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist
sudo rm -rf /Library/Preferences/com.oracle.java.Helper-Tool.plist
Rachit Mishra
  • 6,101
  • 4
  • 30
  • 51
Samuel Alpoim
  • 7,940
  • 1
  • 12
  • 4
  • 2
    Only problem is that now it won't let me install jdk7. I run the installer but the command line still says "No Java runtime present, requesting install"... it's lying though because it doesn't request the install. – geoidesic Sep 17 '14 at 22:05
  • Marvellous! Works like a clock. I was able to downgrade from 8 to 7 applying this advice. – Alexey A. Oct 14 '14 at 00:15
  • I was screwing around with having to figure out what was causing Google App Engine to use Java 8 and sure enough this was the reason. I have no idea how this happened but this is the correct answer. – Axwack Nov 20 '14 at 02:52
  • This looks to be an effective solution for Yosemite (10.10.x) upgrades as well. – JJ Zabkar Apr 28 '15 at 22:03
  • 4
    This is really bad because you're also deleting the preference pane in System Preferences. Just run the first command and leave the others out. – Aquarelle May 05 '15 at 04:36
  • 1
    Also, after this steps, MAC automatically takes alternative java as default if already installed. – Ashokchakravarthi Nagarajan Jun 06 '15 at 12:12
  • 13
    Just to be clear, this is to uninstall all Java stuff. If you for some reason want to keep a different version of Java around, don't remove anything but the JDK itself (first command). – mikl Oct 09 '15 at 21:03
  • 1
    Most "remove Java" guides only remove Java plugins. Thank you for providing a complete answer which actually removes the JDK. I should note that the reason I needed to do this was because Scala 2.11.8 is incompatible with Java 9 and crashes when you try to run it in the terminal. I searched for a while to try to find this. – awwsmm Jan 17 '18 at 19:44
  • and this command to list the versions `ls /Library/Java/JavaVirtualMachines/` – GONeale Jun 18 '18 at 03:39
  • 1
    This was a great hint to the steps I needed to take. One note: the first command should be more broad to cover JDK like "openjdk-12.0.1.jdk" i.e. `sudo rm -rf /Library/Java/JavaVirtualMachines/*jdk*.jdk` to cleanse all JDK. – ldmtwo Apr 25 '19 at 21:49
  • Best way to get the JDK filename is to first query for it using `/usr/libexec/java_home -V` – michael_vons Jan 21 '23 at 14:37
125

You just need to use these commands

sudo rm -rf /Library/Java/*
sudo rm -rf /Library/PreferencePanes/Java*
sudo rm -rf /Library/Internet\ Plug-Ins/Java*
ci0ccarellia
  • 795
  • 9
  • 26
Jonny T S
  • 1,291
  • 1
  • 8
  • 3
16

Managing Java versions on Mac OSX is a nightmare. I recently switched over to using JDK 1.7, deleting JDK 6 from my MacBook entirely (I also had traces of JDK 5 - this laptop has been updated a few times).

Here's what I did to move to JDK 7.

1) download the latest from Oracle (http://www.oracle.com/technetwork/java/javase/downloads/index.html) and install it.

2) Remove (using rm - if you've got backups, you can revert if you make a mistake) all the JDK6 and JRE6 files.

At this stage, you should see:

% ls /Library/Java/JavaVirtualMachines/
jdk1.7.0_nn.jdk

(and nothing else)

3) In the folder /Library/Java/Extensions/, you'll need to remove all the old jar files, the ones that correspond to other releases of Java. If you don't, you'll get the infamous message about the wrong version of tools.jar (see Builds failing after upgrading to Java7, Missing Tools.jar and bad class versions). It is not enough to rename the jar files, because Java will open every jar in that folder - I moved mine into a sub-directory. It's safe to remove them once you know everything else works.

I haven't found I need to set JAVA_HOME for simple things.

Note: I just tried running IntelliJ and it will not start unless you have Apple's JDK 6 installed (see http://youtrack.jetbrains.com/issue/IDEA-93710). Same is true for Eclipse. Netbeans works fine.

Community
  • 1
  • 1
kmorris
  • 654
  • 4
  • 6
  • 1
    Edited original question to include a link to another SO question about getting IntelliJ to use JDK7 (on Mac). – Rob Sep 27 '13 at 23:12
  • 3
    Managing Java version on Mac is an ABSOLUTE NIGHTMARE. I was able to install Oracle Java 8 and manage different Java versions on Ubuntu in under 5 minutes. I have spent several hours now trying to get Oracle Java 8 up and running on OSX. – JohnMerlino May 21 '14 at 15:51
11

Use /usr/libexec/java_home ; I found these alias and function to be pretty useful in my ~/.profile:

alias java_ls='/usr/libexec/java_home -V 2>&1 | cut -s -d , -f 1 | cut -c 5-'
function java_use() {
    export JAVA_HOME=$(/usr/libexec/java_home -v $1)
    java -version
}
Grégory Joseph
  • 1,549
  • 16
  • 14
  • I think this will only work for your shell environment not the environment an app (like Intellij) gets when you double click its icon. – NBW Mar 18 '14 at 20:42
  • @NBW AFAIK Java apps on OSX have their own Java Version set in their Info.plist file (or something along those lines, e.g what version range they support or something). The change to JAVA_HOME will only apply to the current terminal session, but I think /usr/libexec/java_home might impact other sessions/environments. (I can't easily verify it, cause I force java_use 1.7 in my ~/.profile) – Grégory Joseph Mar 19 '14 at 10:44
  • And if you also want to see if the JDK is 32bit or 64bit, something along the lines of `alias java_ls='/usr/libexec/java_home -V 2>&1 | sed "/^ \(.*\) \(.*\),/!d;/^\s*$/d;s/^ \(.*\) \(.*\), \(.*\):\(.*\)$/\2 (\3)/g"'` will do. – ikaerom Oct 12 '15 at 23:42
11

I nuked everything Java, JDK, and oracle. I was running Java 8 on OSX El Capitan

Other answers were missing tons of stuff. This answer covers a lot more bases.

Good bye, shovelware.

sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
sudo rm -rf /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist
sudo rm -rf /Library/Preferences/com.oracle.java.Helper-Tool.plist
sudo rm -rf /System/Library/Frameworks/JavaVM.framework
sudo rm -rf /var/db/receipts/com.oracle.jdk8u65.bom
sudo rm -rf /var/db/receipts/com.oracle.jdk8u65.plist
sudo rm -rf /var/db/receipts/com.oracle.jre.bom
sudo rm -rf /var/db/receipts/com.oracle.jre.plist
sudo rm -rf /var/root/Library/Preferences/com.oracle.javadeployment.plist
sudo rm -rf ~/Library/Preferences/com.oracle.java.JavaAppletPlugin.plist
sudo rm -rf ~/Library/Preferences/com.oracle.javadeployment.plist
sudo rm -rf ~/.oracle_jre_usage
Community
  • 1
  • 1
Mulan
  • 129,518
  • 31
  • 228
  • 259
8

Here is the official document about uninstalling the JDK.

http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096903

Lonre Wang
  • 2,265
  • 1
  • 16
  • 16
  • Just did this again, this did not work. Ended up with 'you have a newer version (and its dead link).' – Rob May 04 '14 at 14:47
  • 3
    This links said: `cd '/Library/Java/JavaVirtualMachines/'`, then `sudo rm -rf YOURVERSION.jdk`, i.e. `rm -rf jdk1.8.0_06.jdk` – Alan Dong Sep 10 '14 at 00:43
4

If you have installed jdk8 on your Mac but now you want to remove it, just run below command "sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk"

Danny Shi
  • 59
  • 1
  • After deleting the jdk folder, an entry for Java still shows up in Launchpad -> System Preferences – Drew Apr 10 '14 at 00:49
  • This worked for me too.... Thanks a ton, helped fix the Fixing Unsupported major.minor version 52.0 Error in Android Studio also. – Pradeep Chakravarti Gudipati Jul 26 '16 at 07:51
  • @Drew from what I can undertand, the Java in prefernces is nothing to do with the JDK (preferences is the one that loads web pages on your machine for instance, JDK is about compilation of other programs using Java), so having it in preferences isn't actually a problem – DaveRGP Apr 26 '17 at 13:54
4

Two ways you can do that:

  1. Removing JDK directly from Users-> Library -> Java -> VirtualMachines -> then delete the jdk folder directly to uninstall the java.

  2. By following the command: (uninstall java 1.8 version )

make sure you are in home directory by using below command, before you write the command:

cd ~/

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.jdk
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/Application\ Support/Oracle/Java
Stephen
  • 9,899
  • 16
  • 90
  • 137
2

To uninstall java of any version on mac just do:

sudo rm -fr /Library/Java/JavaVirtualMachines/jdk-YOUR_ACCURATE_VERSION.jdk/ 
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin 
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
Karthik damodara
  • 1,805
  • 19
  • 17
1

If you uninstall all the files but it still fails, use this line:

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk
Chris Mukherjee
  • 841
  • 9
  • 25
1

You can just locate the Java versions inside the /Library/Java on MacOS and delete the version folder you want to delete and keep the one you need. It works fine. No problem at all.

whatsinthename
  • 1,828
  • 20
  • 59
0

in Mac Remove Java Version using this 3 Commands

java -version

sudo rm -rf /Library/Java/*

sudo rm -rf /Library/PreferencePanes/Java*

sudo rm -rf /Library/Internet\ Plug-Ins/Java*

Run

java -version

//See java was successfully uninstalled.

java -version sudo rm -rf /Library/Java/* sudo rm -rf /Library/PreferencePanes/Java* sudo rm -rf /Library/Internet\ Plug-Ins/Java*

Run java -version

Install Java 8 Link

enter image description here

Download Package and click next next next

Keshav Gera
  • 10,807
  • 1
  • 75
  • 53
0

Official recommendation

https://www.java.com/en/download/help/mac_uninstall_java.html

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java
Nasif Md. Tanjim
  • 3,862
  • 4
  • 28
  • 38
  • 1
    I tried this, and restarted, but this still leaves the java binaries in /usr/bin which is also in $PATH usually – D4NT3 Jun 24 '22 at 10:57
-12

This worked perfectly for me:

sudo rm -rf /Library/Java/JavaVirtualMachines
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
Qiu
  • 5,651
  • 10
  • 49
  • 56