Please use below command :-

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`
Answer from Madhurish Gupta on Stack Overflow
🌐
Oracle
java.com › en › download › help › mac_install.html
How do I install Java for my Mac?
If you are installing another version, make sure you change the version number appropriately. Example: For Java 8 Update 311 (8u311) the file to download is jre-8u311-macosx-x64.dmg · To confirm installed Java version, refer to instructions page here: https://www.java.com/en/download/help/version_manual.html · Note: Below instructions are specific to macOS Big Sur (11.x) 1.
🌐
Apple Developer
developer.apple.com › forums › thread › 655774
java/javac on Big Sur | Apple Developer Forums
Type this command in terminal: "/usr/libexec/java_home" You should get something like: "/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home" Now edit </Applications/NetBeans/Apache NetBeans xx.x/Contents/Resources/NetBeans/netbeans/etc/netbeans.conf> and search for netbeansjdkhome.
Discussions

change java version in macOS BigSur - Stack Overflow
To change the java version from console, use: java8, java11 or java17 ... I have been confused with the same issue today after upgrade macOS to Big Sur. More on stackoverflow.com
🌐 stackoverflow.com
Java enterprise development on MacOS Big Sur

Nothing strange so far.. everything you listed works as before on my one-day-of-work.

More on reddit.com
🌐 r/java
30
31
November 14, 2020
macos - Java works not well after upgrage Mac OS to Big Sur(v11.0.1) - Stack Overflow
Background: I use Macbook pro to develop java app, it works well. While, after i upgraded mac os from 10.x to the latest version Big Sur, mvn clean package threw below exception: [ERROR] Failed to More on stackoverflow.com
🌐 stackoverflow.com
java - Wrong JAVA_HOME after upgrade to macOS Big Sur v11.0.1 - Stack Overflow
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,... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Code2care
code2care.org › home › howto › how to install java on macos [big sur]
How to install Java on macOS [Big Sur] - Code2care 2023
January 26, 2026 - Java would get installed in Library/Java/JavaVirtualMachines/ location. ⚠️ macOS: Catalina, Mojave, Big Sur Java version: 8, 9, 10, 11, 12, 13, 14, 15
🌐
DEV Community
dev.to › pablohs1986 › macos-users-java-problems-in-big-sur-help-7pa
Big Sur Java: MacOS users, Java problems in Big Sur? HELP - DEV Community
November 17, 2020 - Does anyone feel the same? Possible solution? Is this the fault of Apple, Java, or the IDE developers? ... To this day (11/17/2020), we still have no solution for NetBeans. I have finally tried IntelliJ and it works perfectly with Big Sur.
🌐
Reddit
reddit.com › r/java › java enterprise development on macos big sur
r/java on Reddit: Java enterprise development on MacOS Big Sur
November 14, 2020 -

Hello guys! Has anyone updated?
How's it everything working on MacOS update Big Sur as enterprise developer?
Are there any problems, issues present?
Interested in working of such stack:

  • Docker

  • Java 8/11/etc.

  • Intellij Idea

  • etc...?

Being newB around here, so sry if have chosen mistaken thread or something.

Top answer
1 of 2
7

Reason: In ~/.bash_profile, JAVA_HOME= $(/usr/libexec/java_home), after upgraded, $(/usr/libexec/java_home) link to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java which doesn't exist in my disk, so jdk is missing.

Solution: I delete jdk in /Library/Java/JavaVirtualMachines and reinstall jdk8, and then set JAVA_HOME as:

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

instead of soft link and source ~/.bash_profile to let it work.

My full settings:

kevinMacBook-Pro:bin kevin$ cat ~/.bash_profile
export M2_HOME=/usr/local/apache-maven-3.6.3
#Mac OSX 10.5 or later version need this configure
#export JAVA_HOME=$(/usr/libexec/java_home)
#Mac 11 need this configure
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
export MySQL_HOME=/usr/local/mysql

Now, jdk works, after mac os upgraded, it indeed update the soft link of $(/usr/libexec/java_home) and link to a not existed link, so i think you don't need to delete your jdk, just update env variables and re-open terminal to check if jdk reset correctly.

2 of 2
0

Find you JDK location (mine was /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home).

  1. In terminal vim ~/.bash_profile (resp. edit the file in any way you're used to)
  2. Add a line exporting your JDK location (in my case it was export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home)
  3. In terminal source ~/.bash_profile
  4. In terminal echo $JAVA_HOME to make sure the environment variable is set properly
Find elsewhere
Top answer
1 of 11
60

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:)

2 of 11
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
🌐
MacRumors
forums.macrumors.com › macs › macos › older macos versions › macos big sur (11)
Java 6 runtime "legacy version" for MacOS Big Sur 11.3 | MacRumors Forums
January 1, 2021 - FWIW - this did not work - Big Sur 11.3 ... There is quite simple solution: 1. install brew (package Manager for macOS) 2. run in the terminal: brew install java6 As a result you will have jdk 1.6 on the path /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home One thing to note: jdk 1.6 will not work on Apple Silicon.
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 1700
Error in every java file after updating to macOS Big Sur · Issue #1700 · redhat-developer/vscode-java
November 17, 2020 - I started getting this message at the beginning of every java file that i open in vscode saying: ¨The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class filesJava(16777540)¨ The extension that caus...
Author   redhat-developer
Top answer
1 of 2
4

Can confirm this is still happening on adoptopenjdk14, as well as openjdk early access build for j16.

You can file a bug if you want, but I bet it'll be denied. At this point, the name Mac OS X is not so much 'the name of the OS' as a 'globally agreed upon keyword identifying that unix-based mac operating system', where I mean globally literally (as in, 'around the planet', not 'across your source base/VM'). Changing it would just break stuff needlessly. The same applies, to a lesser degree, to version 10.16: The thing before the dot is not so much 'this is how the OS identifies itself' and more a 'globally agreed upon versioning scheme for Mac OS, identifying a wide and ill defined set of capabilities'.

There is no meaningful difference between the transition between big sur and catalina, other than the fact that apple made a marketing decision. If you want to point at an OS transition that might warrant the entirely nebulous choice to consider it a 'major change', surely it was the one to catalina, as that made by far the largest changes (including removing support for 32-bit entirely) in the last bunch of releases.

This leaves you with the challenge of: Okay, great, I can use System.getProperty("os.name") to get the globally agreed upon keyword that means unix-like Mac OS, and os.version for a string I can break into bits to figure out some nebulous batch of capabilities, but what if I need the actual name of the OS to e.g. show to a user?

Then you have three major options:

  1. The easy one is to just write mapping code. Acknowledge that os.name and os.version give you (rather arguably) useful intent and not so much official names, and therefore, write some mappings. These would map name/version pairs to rendering strings, falling back to just printing the name string and the version string, concatenated, verbatim. You could add a mapping: Mac OS X/10.16Mac OS Big Sur in this table.

  2. The hard way: Figure out you're on a mac (which is now easier; os.name returns Mac OS X, or just check for the existence: Files.isExecutable(Paths.get("/usr/bin/sw_vers"))), and then use ProcessBuilder to execute /usr/bin/sw_vers, picking up all output into a big string, and then parse it. Its output looks like:

ProductName:    macOS
ProductVersion: 11.1
BuildVersion:   20C69

which, crucially, doesn't even include the words Big Sur, but does give you 11.1. I don't know how to run a command line tool that actually gives you Big Sur. Maybe system_profiler, but note that this takes many minutes to run, I really doubt you want to run that.

NB: you can also run .command("/usr/bin/sw_vers", "-productVersion") which gives you just 11.1, this may be a lot simpler to parse. -productName also works, gives you just macOS.

  1. If you need this information to scan for OS capabilities, then stop doing this. It doesn't work with browsers, and it's not a good plan for OS releases either. What capability are you scanning for? Imagine, for example, if it is 'Can I run /usr/bin/sw_vers to figure stuff out', as a hypothetical example. The right strategy is NOT to check os.name/os.version, conclude that the command must exist, and then run it, failing catastrophically if it is not there. The right move is to check if /usr/bin/sw_vers exists, and then execute it, falling back to some non-mac based solution (perhaps /usr/bin/uname) in other cases. Scan for the capability, don't scan for the OS/version.
2 of 2
2

Java code to call native tool sw_vers

Regarding Option # 2 in the Answer by rzwitserloot, here is a complete code example to run from Java a command-line tool sw_vers that describes the version of macOS software running on the host computer.

If on the command-line (console) such as in Terminal.app, you run:

sw_vers

…in Big Sur on an Intel Mac we get:

ProductName:    macOS
ProductVersion: 11.2
BuildVersion:   20D64

We only need the middle piece. So running:

sw_vers -productVersion

…shows simply 11.2, the value we need for your purpose.

Here is complete example app with a method to return this string into Java.

ProcessBuilder class creates operating system processes. Each new process is represented by the Process class.

We use try-with-resources syntax to automatically close the InputStream and Scanner objects.

Once you have the 11.2 string in hand, split on the FULL STOP, pull the first number 11, and you know you are running on Big Sur.

package org.example;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * Example code showing how to get current version of macOS from Java
 * by running a native command-line tool `sw_vers`.
 */
public class App
{
    public static void main ( String[] args )
    {
        App app = new App();
        app.demo();
    }

    private void demo ( )
    {
        String version = this.getMacOsVersionNumber();
        System.out.println( "version = " + version );
    }

    public String getMacOsVersionNumber ( )
    {
        String result = "";
        List < String > command = List.of( "sw_vers" , " -productVersion" );
        try (
                InputStream inputStream = new ProcessBuilder( command ).start().getInputStream() ;
                Scanner s = new Scanner( inputStream ).useDelimiter( "\\A" ) ;
        )
        {
            result = s.hasNext() ? s.next() : "";
        }
        catch ( IOException e )
        {
            e.printStackTrace();
        }
        return Objects.requireNonNull( result );
    }
}
🌐
Apple Community
discussions.apple.com › thread › 252192482
How can I find my Java version in Big Sur? - Apple Community
This device is supposed to be ... version of macOS is not available". 2639 4 ... Dec 18, 2020 7:43 AM in response to Paul McG. Yes, Java support is included with the OS....
🌐
Apple Community
discussions.apple.com › thread › 252101382
macOS Big Sur Java Plugin - Apple Community
November 28, 2020 - I have tried current versions of Java as well as previous versions. No errors, it just does not show the available plugin within either of the browsers. Any one else seen this? ... Default browser selection completely broken after Monterey 12.5 upgrade After upgrading to macOS Monterey 12.5, default browser registration and selection is completely broken.
🌐
Oracle
java.com › en › download › apple.jsp
Download Java
下载适用于 macOS ARM64 的 Java 下载 Java 表示贵方确认已阅读并接受适用于 Oracle Java SE 的 Oracle 技术网许可协议的条款。 Oracle Java 许可重要信息.
🌐
Reddit
reddit.com › r/javahelp › java on macos big sur vscode isn't working
r/javahelp on Reddit: Java on MacOS Big Sur VScode isn't working
November 15, 2020 -

I updated to big Sur yesterday and when I try programming in java on vs code everything is throwing an error literally every line. some of my code that was working completely fine before I updated will not compile now. Please help I have a Java test Monday and I need to figure this out.

Top answer
1 of 5
2
I faced this issue too. I managed to find a solution. Open ~/.zshrc(or ~/.bash_profile if you use bash) on a text editor and make sure it contains the following statement somewhere(if it doesn't, add it): export JAVA_HOME=`/usr/libexec/java_home` Save the file, reload your terminal. Run echo $JAVA_HOME. It should return something like /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home. Reload VSCode. That should do the trick.
2 of 5
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Medium
medium.com › @akhiltheguitarist › setting-up-java-path-on-macos-11d51e89a55f
Setting up java path on macOS. So recently, I changed my work machine… | by akhil | Medium
September 24, 2021 - So recently, I changed my work machine to a mac. I was trying to find ways to setup java. It is a bit different to set up on a mac, than in windows. To keep it short, following the below steps helps set the required java home path. The below is verified for macOS Big Sur, v11.6 ·
🌐
Oracle
java.com › en › download › help › java_mac.html
Installing and using Oracle Java on macOS
Information about Oracle Java for Mac - Install, remove, revert Apple Java 6, configure, system requirements