283

Even though JRE 8 is installed on my MAC OS Yosemite 10.10.3,while running the Android present in tools in sdk - the error - " No Java Runtime present,requesting to install " gets displayed in terminal- how do i solve this issue?

  1. I wanted to install Xamarin test recorder - after installing they asked me to install Android sdk

  2. SDK is downloaded in Library/Developer/Xamarin/android-sdk

  3. Now when I run Android present in tools folder - I get the error - No Java run time

  4. I've installed JRE 8 with get the verified java version from their site

Can someone please help!!

8
  • 2
    What happens if you type "java -version" into the terminal?
    – abalos
    May 16, 2017 at 18:38
  • 2
    What happens if you type echo $JAVA_HOME into the terminal? May 16, 2017 at 18:39
  • @BobDalgleish the environment variable JAVA_HOME does not need to exist.
    – andih
    May 16, 2017 at 18:44
  • 3
    You need to install the jdk, not only the jre May 16, 2017 at 18:51
  • This probably belongs on apple.stackexchange.com
    – Kylar
    May 16, 2017 at 19:11

22 Answers 22

236

You have to install the full JDK, not only the JRE.

I had the same issue and solved by installing JDK.

Please use this link to download the latest JDK version 21.

4
  • I got this error while adding Debug signing certificate SHA-1 keys to firebase ,for mac just download the mac os installer and install it once done, and run the command debug certificate generation command and it works Mar 19, 2020 at 7:05
  • yes, you have to install JDK within your Mac OS to get rid of this error.
    – Siddharth
    Mar 30, 2021 at 15:08
  • 20
    This doesn't fix the problem for the latest JDK on macOS 10.15.7.
    – jvriesem
    Apr 29, 2021 at 21:15
  • 8
    This solution didnot work for Monterey (12.4). after installing JDK also $JAVA_HOME is empty
    – Anuj Gupta
    Jun 15, 2022 at 9:01
168

After installing openjdk with brew and runnning brew info openjdk I got this:

==> openjdk: stable 21 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk/21 (600 files, 331MB)
  Poured from bottle using the formulae.brew.sh API on 2023-09-26 at 11:06:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✔, pkg-config ✔
Required: giflib ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, little-cms2 ✔
==> Requirements
Build: Xcode (on macOS) ✘
Required: macOS >= 10.15 (or Linux) ✔
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
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="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"

And from that I got this command here, and after running it I got Java working

sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
10
  • Running in macOS 10.15.7 Catalina, I additionally needed to set my PATH. Feb 5, 2021 at 21:09
  • 8
    Yes! Bang on. I guess it's as simple as "RTFI" Mar 6, 2021 at 23:05
  • Can you elaborate @ChaimLeibHalbert?
    – WJA
    Aug 9, 2021 at 10:41
  • 2
    This is for me the best solution to this issue.
    – zell
    Oct 1, 2021 at 21:21
  • 2
    Thanks! Running on macOS Monterey - 12.4 1- brew install openjdk@11 2- echo 'export PATH="/opt/homebrew/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc 3- sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
    – Cem
    Jul 27, 2022 at 7:48
120

2021 solution

TL;DR

brew install temurin

Details

On an M1 Mac/Apple Silicon (running Big Sur), I had already openjdk installed. As signaled in a previous answer by Mohammed, openjdk is keg-only with brew, and hence requires adding a symlink.

After following this, it solved the No Java Runtime present error, but rJava was complaining about missing libjvm.dylib and that existing libraries were for the wrong architecture:

.onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(jvm, FALSE)
  error: unable to load shared object '/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib':
  dlopen(/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib, 10): 
    no suitable image found.  Did find:
    /opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib: 
    mach-o, but wrong architecture

Installing Eclipse Temurin (previously AdoptOpenJDK) (and removing the previously created symlink in /Library/Java/JavaVirtualMachines/openjdk.jdk) immediately solved both issues seamlessly.

Just run brew install temurin and everything should be OK.

3
  • sh: command not found: brew Nov 26, 2021 at 12:47
  • 3
    @EugeneTroyanskii: brew.sh → Install Homebrew (package manager on macOS)
    – iNyar
    Nov 28, 2021 at 3:43
  • 1
    This is the only working solution
    – AleGiovane
    May 16 at 16:55
83

I didn't need the full JDK, I just needed to make JRE work and none of the other answers provided above worked for me. Maybe it used to work, but now (1st Jul 2018) it isn't working. I just kept getting the error and the pop-up.

I eventually solved this issue by placing the following JAVA_HOME export in ~/.bash_profile:

export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Hope this helps someone. I'm running Mac OS High Sierra.

1
  • I'm also on High Sierra and unfortunately this did work, although it "fixed" the error message "No Java Runtime present". I got this, then: "Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation."
    – Gobe
    Sep 4, 2018 at 17:41
76

I just had to do the following on Mac:

brew install openjdk
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home"
java --version
5
  • 2
    You can export JAVA_HOME="/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home". No need for symlink.
    – nakamume
    Mar 16, 2022 at 3:56
  • 2
    @nakamume Symlink is recommended by Homebrew
    – Saurabh
    Mar 30, 2022 at 3:15
  • 4
    even better the second line: sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk May 16, 2022 at 16:39
  • How I can save this result after restarting macOS?
    – Valeriy
    May 18, 2022 at 11:39
  • 1
    @Valeriy add export JAVA_HOME="..." to your Bash or ZSH profile
    – Saurabh
    May 18, 2022 at 15:16
30

If you came across the error when tried to generate a jks file (keystore), so try adding

/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool

before running the command, like so:

/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
0
17

working by following command

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
4
  • I just run it at Android Studio Terminal and works like a charm, Thanks
    – Sattar
    Mar 21 at 15:18
  • didnt help for my case
    – Waldmann
    Jul 11 at 4:56
  • so open path manually from finder and go until you found jre and copy relative path and export it, like Application=>Android studio=>
    – Rajesh N
    Jul 12 at 4:42
  • 2
    For newer versions of Android Studio: export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home/
    – JoeGalind
    Oct 23 at 17:28
16

Since it sounds like your JAVA_HOME variable is not set correctly, follow the instructions for setting that.

Setting JAVA_HOME environment variable on MAC OSX 10.9

I would imagine once you set this, it will stop complaining.

1
  • 1
    This is the correct answer -- it is enough to install JRE and set JAVA_HOME to make Java command available in shell. May 19, 2018 at 6:52
14

Maybe someone is still having the same issue. You can install openjdk using homebrew, and then add the new JDK bin directory to the front of your path:

cd ~

brew install openjdk

echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> .bash_profile

source .bash_profile
1
  • In my case installed openjdk location was /opt/homebrew/Cellar/openjdk/17.0.1_1/bin
    – SRJ
    Jan 19, 2022 at 5:31
13

Pre-Requisite:

  • I already had java11 installed on my machine using brew.

Step-1: brew info java11

output:

/opt/homebrew/Cellar/openjdk@11

USER1-MacBook-Pro JavaVirtualMachines % brew info java11
openjdk@11: stable 11.0.12 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk@11/11.0.12 (670 files, 273.0MB)
  Poured from bottle on 2021-10-09 at 13:07:04
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/[email protected]
License: GPL-2.0-only
==> Dependencies
Build: autoconf ✔
==> Requirements
Build: Xcode ✘
==> Caveats
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

For compilers to find openjdk@11 you may need to set:
  export CPPFLAGS="-I/opt/homebrew/opt/openjdk@11/include"

==> Analytics
install: 44,188 (30 days), 149,578 (90 days), 433,845 (365 days)
install-on-request: 19,074 (30 days), 63,262 (90 days), 187,286 (365 days)
build-error: 0 (30 days)

Step-2: Append openJDK path to existing path.

echo 'export PATH="/opt/homebrew/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc

Step-3: Source existing shell or open new terminal to validate changes

  • source ~/.zshrc

Step-4: Check path is added

  • which java

output: /opt/homebrew/opt/openjdk@11/bin/java

Step-5:

  • java --version
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment Homebrew (build 11.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)
1
  • It helped me kind of, but after this, I can't run Homebrew: zsh: command not found: brew Jun 7, 2022 at 13:19
7

I solved the problem by installing oracle-sdk with brew.

brew install oracle-jdk --cask
0
6

TL;DR

For JDK 11 try this:

To handle this problem in a clean way, I suggest to use brew and jenv.

For Java 11 follow this 2 steps, first :

JAVA_VERSION=11
brew reinstall jenv 
brew reinstall openjdk@${JAVA_VERSION}
jenv add /usr/local/opt/openjdk@${JAVA_VERSION}/
jenv global ${JAVA_VERSION}

And add this at end of your shell config scripts
~/.bashrc or ~/.zshrc

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"

Problem solved!

Then restart your shell and try to execute java -version

Note: If you have this problem, your current JDK version is not existent or misconfigured (or may be you have only JRE).

8
  • java -version works for me, but apt can't find it. For example, when I do apt update I get the error The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt.
    – raphisama
    Aug 1, 2021 at 6:19
  • Are you trying to run this on MacOS?
    – freedev
    Aug 1, 2021 at 6:24
  • 1
    Yes running on BigSur
    – raphisama
    Aug 1, 2021 at 18:37
  • But AFAIK apt is not available on MacOS
    – freedev
    Aug 1, 2021 at 19:18
  • as always, the instructions don't work. when I try the first jenv (after the brew installs), I get the error: "ln: /Users/ekkis/.jenv/versions/openjdk64-11.0.10: No such file or directory"
    – ekkis
    Aug 4, 2021 at 5:39
6

In 2022:

No need to download Java anymore, once Android Studio is installed.

Even though Java 11 is embedded with Android Studio now, on Mac sometimes this problem arises and the Java runtime is not found.

So, I have solved this problem by doing these two steps:

  1. In Android Studio go to File > Project Structure. If, under the SDK entry, you can see there is no default SDK selected, but a text in red "No SDK", click on it and you will find an SDK / JDK list, select one of them. Thats it.
  2. Make sure you run Android Studio from Application Folder. For this copy the Android Studio launcher to the Application folder. Then in the Finder, go to the Application folder. Right-click on it. Click on "Show package contents", then navigate up to jre folder. Copy the folder and paste it into your home folder.

Now setup the path from the terminal: you can create a folder named java_jre, and the path must be set to jre/contents/Home :

Noors-Mac-mini:bin noorhossain$ export JAVA_HOME="/Users/noorhossain/java_jre/jre/Contents/Home"

// now checking the version :

Noors-Mac-mini:bin noorhossain$ java -version

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
0
6

In 2022, only if Android studio is installed:

  1. Check if JDK is installed in Android studio. In Android Studio go to File > Project Structure. Under the SDK entry, if there is no default JDK selected, select from the list, or if there isn't any, add JDK and then apply to install.

  2. After the JDK is installed in Android studio, you just need to add the JDK path directly from your Android Studio. Run the below command in the terminal and that's it.

echo 'export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"' >> ~/.zshrc
  1. Now, check if it's working.
❯ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)

No need to install any package from brew or create any symlink. The Java is already embedded with the Android studio and we can use this directly for our system.

4

In newer versions of OS X (especially Yosemite, EL Capitan), Apple has removed Java support for security reasons. To fix this you have to do the following.

  1. Download Java for OS X 2015-001 from this link: https://support.apple.com/kb/dl1572?locale=en_US
  2. Mount the disk image file and install Java 6 runtime for OS X.

    After this you should not be seeing any of the below messages:

    - Unable to find any JVMs matching version "(null)"

    - No Java runtime present, try --request to install.

    This should resolve the issue for the pop-up shown below: enter image description here

1
  • 3
    But that is a super old Java. Installing it is a security risk as it is not updated any more.
    – Martin
    Nov 28, 2017 at 13:08
3

Error

error terminal when try to find java version:

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

abdallahandroid@Abdallah-mahmoud ~ % java -version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

error when try to run "flutter doctor"

Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.

try to fix by using "brew"

1- install homebrew :

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2- install java by brew

abdallahandroid@Abdallah-mahmoud ~ % brew install java

3- set export pat

export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"

case set forever by using editior " vim /etc/paths "

/opt/homebrew/opt/openjdk/bin

must restart sometime the mac itself !!, some time not just need to restart termnial

4- test installation

java -version
2

Below is worked for me on macos mojave 10.14.6 version

I installed current jdk(https://www.oracle.com/java/technologies/javase-downloads.html)

Then do respectively;

  • vim .bash_profile
  • add "export JAVA_HOME=$(/usr/libexec/java_home)" to bash_profile
  • source .bash_profile

it is done. And you can check the version with java -version command.

2

If you are having this issue for the same reason that I am, I can tell you why it is happening. I just don't know how to fix it yet.

Here it is:

I am using JDK version 1.8 on MacOS Big Sur. I do not want to have to install a later version of the JDK because all my projects run on 1.8. But here's the thing.... On the command line

java -version

Returns this:

openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-bre_2021_08_14_21_34-b00)
OpenJDK 64-Bit Server VM (build 25.302-b00, mixed mode)

but a slightly different command (version prefixed with 2 dashes instead of 1)

java --version

returns this error:

Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

This is because Java 8 uses single dash version, all JDKs after use double dash.

So the machine, when looking for JAVA_HOME, is also using double dashes and getting the error.

2

just run this

sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
1

I have Mojave 10.14.6 and the only thing that did work for me was:

  • setting JAVA_HOME to the following:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
  • source .bash_profile (or wherever you keep your vars, in my case .zshrc)

Hope it helps! You can now type java --version and it should work

1

It's worth noting that with my current version of SQLDeveloper (21.2.1), there's another way to specify the JDK location. In my case, I was able to open up ~/.sqldeveloper/21.2.1/product.conf and set the JavaHome directive to the appropriate directory. I use jabba for JDK version management, and this path was something like ~/.jabba/jdk/[email protected]/Contents/Home. Needless to say, just setting that config value and restarting SQLDeveloper left me with a running copy again. This should work with any version of SQLDeveloper given the product.conf file exists inside your user's .sqldeveloper directory appropriate for the version you are using.

-3

install JDK it will work ,

here is the jdk link to download .

link: https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads- 5672538.html

Not the answer you're looking for? Browse other questions tagged or ask your own question.