Wrong JAVA_HOME after upgrade to macOS Big Sur v11.0.1
Asked Answered
G

11

45

In my setup on macOS I'm working with several JDKs, switching between them via /usr/libexec/java_home tool, similar to a method described in this SO answer

After upgrading to macOS Big Sur v11.0.1, my JAVA_HOME setting stopped working, always reporting the same java version:

% /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
    11.0.8 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
    1.8.162.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_162 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
    1.8.0_45 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
    1.7.0_45 (x86_64) "Oracle Corporation" - "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

% /usr/libexec/java_home -v 1.8.162.12
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

% /usr/libexec/java_home -v 1.7.0_45
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Gargle answered 19/11, 2020 at 18:24 Comment(2)
You may find the answers from JAVA_HOME in MacCuneal
I can't reproduce this problem at all, on any of the Macs I have access to. But then I also don't have the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin mentioned below on any of them.Sadoff
G
58

Seems in macOS Big Sur v11.0.1 the behavior of the /usr/libexec/java_home -v ... command has changed: it is sensitive to the previously set value of JAVA_HOME environment variable.

Exact behavior is not clear, I couldn't find any documentation on this, but in my experiments it reported the version already set in JAVA_HOME, regardless of the -v switch:

% JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

Additionally, I noticed that it reports nothing, if JAVA_HOME is set, but doesn't point to a valid java home (also for -V):

% JAVA_HOME=dummy /usr/libexec/java_home -v 1.7.0_45
% JAVA_HOME=dummy /usr/libexec/java_home -V
%

Solution is to ensure JAVA_HOME is not set before executing /usr/libexec/java_home:

% unset JAVA_HOME ; /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
Gargle answered 19/11, 2020 at 18:29 Comment(3)
Seems like a bug to me. I can think of no justification for either its apparent new behavior or for deciding to change it out from under everyone already using its prior behavior. - Maybe someone should Radar this issue.Adriell
Note that this change in behavior in v11.0 was not intentional. It was fixed in v11.2 to return to be consistent with the older behavior for JAVA_HOME.Adelric
This worked for me although the route that led me to this problem of a wrongly set/unavailable JAVA_HOME environment variable. "java -version" command upon execution, gave me all the rightly seeming answers. But upon trying to access the path, it wasn't something that was present indeed. Therefore, I tried unsetting the JAVA_HOME variable using the above command and removed all the other two variable values except for v jdk 11 That resolved the long running issue I had run into, after upgrading to MacOS BigSur. Hope it helps someone else stuck in a similar rabbit hole.Eutherian
A
59

I have Big Sur 11.2.1 from 18.02.2021. I had the same issue with JAVA_HOME path configuration. After reading a lot of information I solved my problem with next:

Install JDK 8: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html Java SE Development Kit 8u281

Install it as usual on your MacOS Big Sur.

Check JDK version:

java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

Check what versions of JDK are already installed on your machine:

/usr/libexec/java_home -V 
Matching Java Virtual Machines (2):
    1.8.281.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_281 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Get only one that you need:

/usr/libexec/java_home -v 1.8.0_281
/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home

On Catalina and Big Sur - there is Z-shell , to add Environment variables like JAVA_HOME there are two files for that: ~/.zshenv and ~/.zshrc, I couldn't make it work with first one. It worked for me like this:

nano ~/.zshrc

Add to that file this line:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_281)

Press Ctrl+X and save changes.

Then run command to apply that changes to current terminal:

source ~/.zshrc

After that you can check if everything is working with command:

echo $JAVA_HOME
it will print you: /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home

Restart your terminal and programs which will be using JAVA_HOME variable. For me it was Android Studio. Now everything works fine. I am new to Mac OS and it took me with 4hours to solve this. With Windows it's just done in a minute:)

Aluminum answered 18/2, 2021 at 21:18 Comment(4)
Following these steps blew away my existing terminal settings. I don't quite remember where they were set, but they are now gone.Expeditionary
Worked for me. I also had run "unset JAVA_HOME ;" before this.Ifill
Thank you, the instruction was clear and worked perfectly. I encountered issues with building android apps in Ionic when my office macbook updated to Big Sur. Even though my device has a lot of restrictions, no special permissions needed to apply this fix. Thank you again.Clerissa
The same is working with JDK 11 as well. Just tested it.Aluminum
G
58

Seems in macOS Big Sur v11.0.1 the behavior of the /usr/libexec/java_home -v ... command has changed: it is sensitive to the previously set value of JAVA_HOME environment variable.

Exact behavior is not clear, I couldn't find any documentation on this, but in my experiments it reported the version already set in JAVA_HOME, regardless of the -v switch:

% JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

Additionally, I noticed that it reports nothing, if JAVA_HOME is set, but doesn't point to a valid java home (also for -V):

% JAVA_HOME=dummy /usr/libexec/java_home -v 1.7.0_45
% JAVA_HOME=dummy /usr/libexec/java_home -V
%

Solution is to ensure JAVA_HOME is not set before executing /usr/libexec/java_home:

% unset JAVA_HOME ; /usr/libexec/java_home -v 1.8.0_162
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
Gargle answered 19/11, 2020 at 18:29 Comment(3)
Seems like a bug to me. I can think of no justification for either its apparent new behavior or for deciding to change it out from under everyone already using its prior behavior. - Maybe someone should Radar this issue.Adriell
Note that this change in behavior in v11.0 was not intentional. It was fixed in v11.2 to return to be consistent with the older behavior for JAVA_HOME.Adelric
This worked for me although the route that led me to this problem of a wrongly set/unavailable JAVA_HOME environment variable. "java -version" command upon execution, gave me all the rightly seeming answers. But upon trying to access the path, it wasn't something that was present indeed. Therefore, I tried unsetting the JAVA_HOME variable using the above command and removed all the other two variable values except for v jdk 11 That resolved the long running issue I had run into, after upgrading to MacOS BigSur. Hope it helps someone else stuck in a similar rabbit hole.Eutherian
R
31

As I tryed. I just delete the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin and relogin. Then everything works fine.

Rheumatic answered 16/12, 2020 at 15:47 Comment(0)
F
13

For me https://developer.apple.com/forums/thread/666681 worked after spending so much time on the solutions.

I simply call following commands

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefpane

Fayina answered 19/1, 2021 at 7:54 Comment(0)
C
1

For me, it is totally broken. Unsetting JAVA_HOME, /usr/libexec/java_home gives:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Catholicity answered 10/12, 2020 at 22:30 Comment(1)
That's one of JVMs on your mac, selected by default - I have the same too. Check what JVMs available calling /usr/libexec/java_home -V, and then get JAVA_HOME for the one you need calling /usr/libexec/java_home -v <ver>.Gargle
O
1

Had this problem after installing Big Sur.

First I started uninstalling all JDK from the system with:

sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin  
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane  
sudo rm -rf /Library/Application\ Support/Oracle/Java/ 
sudo rm -rf /Library/Java/JavaVirtualMachines 

Then, I installed the JDK that I am going to use:

brew tap AdoptOpenJDK/openjdk
brew install --cask adoptopenjdk<version>
Outline answered 25/1, 2021 at 11:34 Comment(0)
C
1

The /usr/libexec/java_home tool in macOS will give you the location of the latest Java version installed. Invoke it from the terminal to get a response similar to the following:

/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home

Navigate into the root and open the .zprofile file.

cd ~
open .zprofile

If the file is not found, create one using the echo > .zprofile command.

Open the file using open .zprofile. This should open it up in a text editor.

Add the response of the /usr/libexec/java_home tool into the file like so:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
Cetacean answered 24/12, 2021 at 7:37 Comment(0)
C
0

$> /usr/libexec/java_home -v "1.8.0" appears to access the exact jdk if present. Ignores the 'plugin' if installed. The quotes were recommended in random places on internet. They are also shown in the man page.

Chiffchaff answered 6/7, 2021 at 23:47 Comment(0)
I
0

My solution is creating a link to your JDK file. Apparently, Teradata studio was executing a wrong path sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/server/libjvm.dylib /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/libserver.dylib

Internationalism answered 24/2, 2022 at 22:44 Comment(0)
L
0

download and install jdk from oracle and then do

sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane

Then jre versions should not appear when you do

/usr/libexec/java_home -V | grep jdk

add export JAVA_HOME=/usr/libexec/java_home -v 1.8 to ~/.zshrc

Longlimbed answered 18/4, 2023 at 8:31 Comment(0)
S
-1

Agree with @Konstantin. I faced the same issue , after the Big Sur upgrade.

The steps you need to follow to fix this are :

  1. unset JAVA_HOME
  2. check what java_home in library is pointing to: /usr/libexec/java_home -v

Matching Java Virtual Machines (2):

1.8.221.11 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

1.8.0_221 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
  1. Because both the versions start with 1.8.221, so by default 1st one is picked, check the version

/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

  1. export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home'
  2. echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

Singer answered 7/6, 2021 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.