Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA gives “The selected directory is not a valid home for JDK” error even it is a valid JDK

I'm trying to set a JDK path and IntelliJ gives this error:

The selected directory is not a valid home for JDK

But I am sure that it is absolutely valid because I can use the java compiler.

javac Main.java compiles the file correctly.

I am sure that the path is also correct because the command below gives me that path.

/usr/libexec/java_home prints the path below:

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

When I choose this path on IntelliJ, it shows the error. I reinstalled the JDK and also tried to choose /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/ but none of them worked.

Please do not consider this question is a duplicate because I tried all of the solutions offered in other answers.

like image 575
amone Avatar asked Jul 15 '18 01:07

amone


People also ask

How do I fix the selected directory is not a valid home for JDK?

First at all, you need to select the C:\ folder. Then, you select Program Files. After it, you select java, and finally the jdk you downloaded.

Where is a valid home for JDK?

Set JAVA_HOME: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.

How do I point to JDK in IntelliJ?

From the main menu, select File | Project Structure | Project Settings | Project. If the necessary JDK is already defined in IntelliJ IDEA, select it from the SDK list.

Do I need to install JDK for IntelliJ IDEA?

You do not need to install Java to run IntelliJ IDEA because JetBrains Runtime is bundled with the IDE (based on JRE 11). However, to develop Java applications, a standalone JDK is required.


2 Answers

For the latest version of Intellij community edition, check their release notes here : https://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+2018.1+181.5540.7+Release+Notes

Seems there's a bug "Manually provided JDK 10 not accepted in JShell: "JDK version is 8"

Hope it helps.

Thanks.

like image 169
dossani Avatar answered Nov 13 '22 09:11

dossani


I had the same issue, but - in my case and I'm pretty confident in your case too - it is not related to the bug presented in the accepted answer. For some reason, IDEA IntelliJ doesn't accept any OpenJDKs. I tried all version from 7 to 9. It worked immediately once I installed the Oracle JDK (version 10 this time).

Also, you might have multiple JDK installed and when running the java command in the terminal - without knowing - you may be actually using a different JDK than the one you think you're using.

Use which java and then ls -l the resulted path to see what's behind the symlink.

like image 26
Ionut Ciuta Avatar answered Nov 13 '22 10:11

Ionut Ciuta