Fix [Mac Terminal] The operation couldn’t be completed. Unable to locate a Java Runtime. (update for Ventura/Sonoma)

Terminal Java Error:

    The operation couldn’t be completed. Unable to locate a Java Runtime.

    Please visit http://www.java.com for information on installing Java.


Error Screenshot:

    The operation couldnt be completed. Unable to locate a Java Runtime - Mac Terminal Error

Reason for the Error:

    If you have recently purchased a Mac, or simply formatted your macOS to its factory settings, then by default there is no Java JDK (or JVM) pre-installed on your Mac device.

    Hence, when you open the Terminal and run a java or javac command, you will get an error saying this operation couldn’t be completed as the System is unable to locate a Java Runtime.


How to resolve the Error:

    To resolve this Java error, you will need to download and install Java JDK or JRE on your Mac.

    As of year 2023, you can install Java versions from Java 8 to Java 21 on your device. It is recommended to get a stable LTS (Long Term Supported) version of Java.

    List of Java LTS Versions:

    1. Java 8
    2. Java 11
    3. Java 17
    4. Java 21

    Also, depending upon what type of Mac device you have - Intel Based / M1/M2 Max/Ultra you would need a different kind of setup to run Java natively on your device.


    Mac Type vs Java installations:

    Mac Chip/Processor Type Java Compatibility
    Apple Silicon (M1/M2) ARM64 (Java 11 and later)
    Intel x86 x86_64 (Java 8 and later)

    You can install x86_64 Java Setup on a M1/M2 based ARM Mac, but the performance will not be at optimum.


    Finally there is a list of Java distributions to choose from,

    • OpenJDK
    • Oracle JDK
    • AdoptOpenJDK
    • Azul Zulu
    • Amazon Corretto
    • IBM JDK
    • SAP Machine
    • Red Hat OpenJDK
    • Microsoft Build of OpenJDK
    • BellSoft Liberica JDK
    • GraalVM

    Java 8/11/17 Installation Steps

      Instead of download the setup from a website, we can easily install Java on your Mac using package manager like Homebrew.

      • Make sure brew is installed on your Mac. Open Terminal and run the below command to check.
        % brew --version
        zsh: command not found: brew
        

        If you get the above error, instead of version details, follow this article to install brew on your Mac - https://code2care.org/howto/install-homebrew-brew-on-m1-mac


      • To install OpenJDK Java

      • Now simply run the below commands to install Java 8/11/17,
        brew install openjdk@8

        Note: There is only x86_64 support for Java 8 so won't work on M1/M2 based Mac.

        brew install openjdk@11
        brew install openjdk@17

        You need not need to worry about the 64/ARM installation, brew will automatically take care of it.


        To install Amazon Coretto Java JDK

        brew install --cask corretto

        To install Graal VM Java JDK

        brew install --cask graalvm-jdk

        To install Oracle Java JDK

        brew install --cask oracle-jdk

        To install Azul Zulu Java JDK

        brew install --cask zulu

    Install Java by download DMG Setup file


    This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0 and Ventura 13.0.

    Please support independent contributors like Code2care by donating a coffee.

    Buy me a coffee!

    Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!