How to Properly update Java on OS-X - java

I have installed and updated to the latest Version of Java.
I am running OS X 10.11.6 (15G31) on iMac.
The Java Control panel shows the correct verion and shows the link as:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
Executing:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.8.0_101"
Shows the correct version.
However, exectuting:
java -version
java version "1.8.0_45"
shows an old version.
Executing:
whereis java
/usr/bin/java
Shows the link as /usr/bin/java
Yet trying to replace the soft link fails:
sudo ln -fs /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java
ln: /usr/bin/java: Operation not permitted
Even when using:
sudo bash (ie as root)
Any ideas?
Thanks
-jim

As it says in the folder name, /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java is actually an internet plug-in which is most likely only used for Applets.
The plain java installation on a Mac is located in /System/Library/Frameworks/JavaVM.framework/Versions and this seems to be not updated automatically.
Therefore, you'd need to go to http://java.oracle.com and download and install the current Java version from there (it will update an existing Java8 installation automatically during the installation process). After that, /usr/bin/java will point to the updated version.

Related

Installing JRE using homebrew

I used the command brew install openjdk#11 to install Java on my mac. But when I run
java --version, I get the following message:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
I have a few questions:
How do I install JRE using HomeBrew?
Which JRE version do I need to install?
The answer to your question can be found by running:
brew info openjdk#11
Part of the output is:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk#11 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have openjdk#11 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc

Editing PATH for Java

I am using Manjaro GNU/Linux 5.7.0-3 x86_64 and had installed older Java Oracle jdk1.8 previously but now I want to install Oracle jdk14.0.1 which I have unpacked to /opt.
In order to reflect the changes, I edited ~/.bashrc file by adding this line:
export PATH="/home/arjun/anaconda3/condabin:/home/arjun/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/jdk-14.0.1/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
Then executed these to reload the terminal:
source ~/.bashrc
bash;
And I even restarted the computer but still, Java is using the older version:
$ javac -version
javac 1.8.0_252
What's going wrong?
Thanks!
In ArchLinux and manjaro you can use pre-installed archlinux-java utility.
for getting information about all installed java's and current choice, you need status and for change it you can use set
sudo archlinux-java status
sudo archlinux-java set java-14-jdk # or something similar related to java14
read more about it in the wiki
Because of different versions of java are installed, you can change default option with this command.
sudo update-alternatives --config java
With this command, you can select java version as default option.

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.

java's path still /usr/bin/java after brew cask install java

I installed java with homebrew, using the command brew cask install java.
After successfully installing, I typed which java, and the path showed to be /usr/bin/java
When I typed brew cask info java, this showed up:
java: 1.8.0_102-b14 Java Standard Edition Development Kit
/usr/local/Caskroom/java/1.8.0_102-b14 (227.5M)
https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb
Contents JDK 8 Update 102.pkg (pkg) Caveats This Cask makes minor
modifications to the JRE to prevent issues with packaged applications,
as discussed here: If your Java application still asks for JRE
installation, you might need to reboot or logout/login.
Installing this Cask means you have AGREED to the Oracle Binary Code
License Agreement for Java SE at
Did I forget to link something?
/usr/bin/java is a symlink.
To see where it points, type ls -la /usr/bin/java
brew cask is installing into /Library/Java/JavaVirtualMachines/jdk1.8.0_something.jdk/Contents/Home
If the previous command ls -la is matching this, you are good.
If not, it means that you previously had another java installation. In this case, you may want to use a tool like jenv to switch between your multiple installs.
To add to #djangofan .. when I did a brew reinstall, I noticed the following message:
==> Pouring openjdk--17.0.1_1.big_sur.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into
/usr/local, because macOS provides similar software and
installing this software in parallel can cause all kinds of
trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/johndoe/.bash_profile
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
To his point, I did not install via cask. I assume that when you did the install you got a similar message that you simply did not notice.

Categories

Resources