10

I'm having trouble removing Java 9 from my macOS Sierra system.

I accidentally installed Java 9, instead of Java 8, so now all my Eclipse projects give me these warnings: Build path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment.

I have used the following guide, but it did not work. Here is my command output when running java -version from the command line:

java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
4
  • 3
    You should be able to set the target Java version in the settings of Eclipse. Uninstalling shouldn't be necessary. Dec 20, 2017 at 0:20
  • I navigated to Eclipse > Preferences > Java > Installed JREs, but only Java SE 9 is listed.
    – Espin
    Dec 20, 2017 at 0:23
  • Do you have 8 installed? Dec 20, 2017 at 0:24
  • I've tried to install Java 8 numerous times, and when I finish the installation, it says it was "successful", but still, only Java 9 is listed. There is no hard evidence of the Java 8 installation actually doing anything.
    – Espin
    Dec 20, 2017 at 0:29

7 Answers 7

20

for macOS high sierra removing java 9:

delete the java folder you find in the dir shown to you after executing:

/usr/libexec/java_home -V

use "Go to" in finder and copy and paste the dir to get there

1
  • Simplest answer. Worked great on macOS High Sierra Version 10.13.3
    – user674669
    Feb 4, 2018 at 23:57
8

There are two commands which are very simple and useful. If you want to keep multiple versions simply set JAVA_HOME to version you want to use.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_(version you want to use).jdk/Contents/Home

Example--> export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home

Else in addition to above command remove/uninstall additional jdk version from your system with below command.

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-(version you want to remove).jdk/

Example --> sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/

Please refer below github link for additional details --> https://gist.github.com/schnell18/bcb9833f725be22f6acd01f94b486392

Thanks

5

On MacOS you can list what JDKs you have installed and where they are installed to with:

/usr/libexec/java_home -V

If you want to select one of the installed JDKs to be used as default, you can do:

/usr/libexec/java_home -v 1.8

Verify which is now default with java -version.

You can manually add the location of other installed JREs in Eclipse via Preferences / Java / Installed JREs , press Add, and then point it to one of the locations should with the -V option above. You can then check it to select which is default for your projects.

0
2

After viewing which Java Virtual Machines I had on my computer using the following command:

ls /Library/Java/JavaVirtualMachines

I realized no additional JDK's would appear after using the Java 8 installer (besides Java 9). When doing further research, it turns out I had installed the other version that is not a SE development kit and it was just working in web browsers, not for the terminal.

For anyone having the same issue, make sure you use the Java SE Development Kit 8.

1
  • i was about to throw my macbook onto the wall. thanks mate, saved my macbook
    – Ninja
    May 20, 2018 at 0:17
1

Uninstall Oracle Java using the Terminal:

Note: To uninstall Java, you must have Administrator privileges and execute the remove command either as root or by using the sudo tool. Remove one directory and one file (a symlink), as follows:

Click on the Finder icon located in your dock
Click on the Utilities folder
Double-click on the Terminal icon
In the Terminal window Copy and Paste the commands below:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Java

Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.

Source:https://www.java.com/en/

3
  • I tried just that using the guide I mentioned in my original post, but it didn't work. I still have Java installed.
    – Espin
    Dec 20, 2017 at 0:42
  • What is the output of /usr/libexec/java_home -V? You have installed the JDK so there is an additional directory for you to remove, namely /Library/Java/JavaVirtualMachines/jdkX.XX.XX.jdk. See these docs: docs.oracle.com/javase/8/docs/technotes/guides/install/…
    – Matt
    Dec 20, 2017 at 2:17
  • For the first command, the output is Matching Java Virtual Machines (1): 9, x86_64: "Java SE 9" /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home When I went to /Library/Java/JavaVirtualMachines/ there is a jdk-9.jdk, should I remove it?
    – Espin
    Dec 22, 2017 at 21:48
1

I believe the problem is navigating to the correct directory... Once you are where you are supposed to be you can run the sudo commands to remove whichever versions of java you want to remove.

First, run the command in the terminal to determine which version of Java you are running,

java -version

then you can navigate to pesky version of java that you intend to delete by using the following command:

cd /Library/Java/JavaVirtualMachines

then once you see are in the JavaVirtualMachines path, type in ls to see what versions of Java you have installed,

ls

and finally when you know which version or versions of Java you want to uninstall:

sudo rm -rf jdk-10.0.1.jdk #or whichever version you want to delete
0

I know that you've asked about how to uninstall the java version. But, I think it's important how to manage your Java version in a very good way.

For me, the best way is using SDKMan, a very nice tool for managing you Development tools like Java.

Here you can learn more about it: http://sdkman.io/

You can install your Java version as follow:

$ sdk install java

You can install others tools like Scala:

$ sdk install scala 2.12.1

Uninstall your tools very easy:

$ sdk uninstall java 9

And so on. Hope this helps you in future installation of your development tools.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.