Tips on how to uninstall JDK or Java SE in Mac OS X.
1 How to see JDK versions already installed
The java_home -v
command will list all JDKs already installed in your Mac OS.
$ /usr/libexec/java_home -v
Output after executing above command may be similar with following text, which means there was two versions of JDK installed, 1.8.0_121 and 1.7.0_79.
Matching Java Virtual Machines (1):
1.8.0_121, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
1.7.0_79, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
2 How to locate JDK installation folder
Above java_home -v
command has already told you where JDKs were installed.
$ cd /Library/Java/JavaVirtualMachines
$ ls
jdk1.8.0_121.jdk jdk1.7.0_79.jdk
3 How to check which JDK version is currently used by Mac OS
Using java -version
or javac -version
to show the JDK version used by system.
$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
$ javac -version
javac 1.8.0_121
4 How to switch JDK version
Appending following line to your ~/.profile
file will switch system's JDK to 1.8 version.
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
5 How to uninstall JDK
If you decide to remove a JDK version, just simply delete its installation folder.
$ sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk
or
$ cd /Library/Java/JavaVirtualMachines
$ sudo rm -rf ./jdk1.7.0_79.jdk
6 Homebrew or MacPorts
If your JDK was installed using Homebrew or MacPorts, please uninstall your JDK using the same way.