How to uninstall JDK on Mac OS? - java

Folks - I am facing challenges while trying to uninstall JDK from my MAC (macOS High Sierra Version 10.13.4 - 17E199). I have two JDK instances installed and I want to uninstall both of them.
I am following the steps listed on this page: https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html
I am trying to run this command in the /Library/Java/JavaVirtualMachines directory which throws an error that I do not have the permission.
rm -rf jdk1.8.0_06.jdk
I am the administrator of the machine and am not sure what more permission do I need. I have made attempts as the admistrator and as the root user with no success.
Please share your thoughts on this.

From the official Oracle manual.
Navigate to /Library/Java/JavaVirtualMachines and remove the directory whose name matches the following format:
/Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk
For example, to uninstall 8u6:
%rm -rf jdk1.8.0_06.jdk
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.
To remove system files you need to add sudo before rm -rf command.

For MacOS - Big Sur | Using Terminal
I was able to remove OpenJDK as per information provided in below link.
Site Link

If you want to remove JDK from mac you can use the following command:
cd /Library/Java/JavaVirtualMachines/
and then use sudo to remove the jdk because you need root permissions to delete jdk from /Library/Java/JavaVirtualMachines/.
/Library/Java/JavaVirtualMachines/ is owned by root.
sudo rm -rf jdk1.8.0_06.jdk
https://installvirtual.com/uninstall-java-8-mac-os-x/

This answer is correct for JDK 8, but it would be nice to point out that Oracle provides different instructions for each release of the JDK. The link structure changes slightly for some versions, but generally you can go to https://docs.oracle.com/en/java/javase, select your JDK release, and look for the "Install Guide" link in the Overview group.
For example:
JDK 9
JDK 10
JDK 11
Also, the files in /usr/bin are not part of the JDK, so you don't really want to remove them. On a system that has never had the JDK installed:
$ ls -l /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Sep 27 17:08 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
$ java -version
No Java runtime present, requesting install.
Apparently macOS includes a baseline version of the JDK, where each command is a stub that just prints this message and pops up a dialog in the GUI.

Related

How to uninstall Java 9 on macOS Sierra

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)
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
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
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.
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.
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/
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
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.

Choose updated Java SDK in mac from available different version

I'm using mac machine for native-script development and while executing an program it thrown an java error that:
Javac version 1.6.0_65 is not supported. You have to install at least 1.8.0.
so I checked with available install version on developer machine & found two different version detail:
/usr/bin/java -version Showing 1.6.
while system preference -> java control panel -> update. showing V1.8
any suggestion why two version !! Am I missing something here?
Update1: Following help to understand how mac handling this: /usr/bin/java is machine default location, and /Library/Internet.. which is manage explicit.
sudo rm /usr/bin/java
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin
In my case I update default one with downloaded from internet.
Reference link Link1, Link2
You should use /usr/libexec/java_home instead
> /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
you can use it to set JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home)
then, you can put this one inside ~/.profile so you have always JAVA_HOME set to most recent release.

How do I install an earlier version of Java SDK on OSX

I have the Java 1.8.0_45 SDK installed on OSX Yosemite (10.10.4), but because of a bug in this release I need to go back to 1.8.0_25
I have downloaded and installed the earlier version (1.8.0_25) but even after a reboot java -versionstill shows 1.8.0_45.
I don't really understand where Java resides on OSX, but how can I get my system back so it uses 1.8.0_25
Try and add this to your ~/.bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
You can have multiple JRE/JDK's installed, by changing this path, you can specify which one you use each time you open a new shell.
Here is what I use in my .bashrc
JAVA_VERSION=7
JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
tmp="JAVA_${JAVA_VERSION}_HOME"
export JAVA_HOME=${!tmp}
export PATH=${!j}/bin:$PATH
Here, you can simply change the 7 to an 8.
This will change the JAVA_HOME, and append the bin directory to your path for general use from the command line.
note you may beed to change your java home's according to the specific release versions installed on your machine.
Ah found it, suprisingly easy:
macbook:JavaVirtualMachines paul$ cd /Library/Java/JavaVirtualMachines
macbook:JavaVirtualMachines paul$ ls
jdk1.7.0_40.jdk jdk1.7.0_45.jdk jdk1.8.0.jdk jdk1.8.0_05.jdk jdk1.8.0_20.jdk jdk1.8.0_25.jdk jdk1.8.0_45.jdk
macbook:JavaVirtualMachines paul$ sudo rm -fr jdk1.8.0_45

update java compiler on mac os

I I donwloaded the last mac os JDK (jdk-8u5-macosx-x64) from the oracle website and install it sucsefully. Reboot the laptop but my java compiler version still the same
javac -version
javac 1.6.0_51
Edit
I just changed the Java_Home variable in ~/.bash_profile to the new one /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home. It works perfectly
Uninstall the current JDK and install jdk-8u5 again.
You can uninstall it using the following:
To uninstall the JDK, you must have Administrator privileges and execute the remove command either as root or by using the sudo(8) tool.
Navigate to /Library/Java/JavaVirtualMachines and remove the directory whose name matches the following format:
/Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk
For example, to uninstall 8u6:
% rm -rf jdk1.8.0_06.jdk
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.
Taken from http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A10969

Eclipse can't find Java, Java not installed

I was following an online tutorial on how to delete JVM 6 and install JVM 7 to be able to run eclipse on my Mac running OS X 10.9.2. First I installed the latest JDK.
I was instructed to type the following commands to delete JVM 6.
sudo rm -rf /System/Library/Java/JavaVirtualMachines/
sudo rm /private/var/db/receipts/com.apple.pkg.JavaForMacOSX*
sudo emacs /Library/Receipts/InstallHistory.plist
Then, I set the symlinks for java 7, with these commands.
sudo rm /usr/bin/java
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/bin/java /usr/bin/java
This should be it. Now my computer does not have any version of Java on it:
the command "java -version" responds with "java: command not found"
I also cannot direct to the folder with cd Library/Java responding with "Folder does not exist", however I can browse to that folder manually.
Can someone please assist me in getting Java 7 running on my computer so I can use eclipse.
Any help much appreciated and keep in mind I'm a Mac newb.
this is the tutorial i followed:
http://www.cc.gatech.edu/~simpkins/teaching/gatech/cs2340/guides/java7-macosx.html
Did you change the PATH variable to point to the newer version?
/usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac.
I think that the folder still exists but executables didn't existe because anh version of Java is installed.
Normally you have just to download the jdk or jre on oracle web site and run the package downloaded

Categories

Resources