IntelliJ IDEA "The selected directory is not a valid home for JDK"
Asked Answered
M

16

90

I just installed IntelliJ IDEA and I'm trying to set it up. I've gotten to the part where I need to select my home directory for my JDK.

I tried navigating to my Java installation, C:\Program Files (x86)\Java, and clicked okay but it told me the message above. So, I tried C:\Program Files (x86)\Java\jre7 and that didn't work either.

I tried reinstalling the latest JDK (from here) and I still couldn't choose my JDK. I even dragged the .jar installer I got from the website and the file selector window wouldn't recognize it.

I'm at a standstill and I don't know what to do.

Metopic answered 11/2, 2014 at 21:29 Comment(0)
L
62

Because you are choosing jre dir. and not JDK dir. JDK dir. is for instance (depending on update and whether it's 64 bit or 32 bit): C:\Program Files (x86)\Java\jdk1.7.0_45 In my case it's 32 bit JDK 1.7 update 45

Lacagnia answered 11/2, 2014 at 21:33 Comment(7)
Is that a file, or directory? Because it's not in my Java folder.Metopic
Then you didn't install your JDK properly. Check wheter your JDK is possibly in: C:\Program Files\Java folderLacagnia
Its a directory, you should have one for each version of JDK installed.Annuitant
Wait, nevermind. It was in Program Files, not Program Files (x86).Metopic
Weird as it states that JDK is bundled: intellij-support.jetbrains.com/hc/en-us/articles/… JDK is bundled with all the product installers and it's recommended that you will use the provided JDK version unless there are any specific issues. 32-bit JDK is located in IDE_HOME\jre directory and is used by the 32-bit product executable.Goodhen
the common mistake is people usually install jre instead of jdkAribold
In my case, pointing to the JDK 9 directory did not work, but pointing to JDK 8 did.Lydia
Q
38

For anyone on a Mac with a homebrew-installed openjdk, you need to use the directory under libexec: <openjdk11_directory>/libexec/openjdk.jdk/Contents/Home.

Thanks to https://intellij-support.jetbrains.com/hc/en-us/community/posts/360007751379/comments/360001513560.

Quota answered 1/10, 2021 at 17:41 Comment(4)
thanks. It's my first time use macOS(M1). 1. make /opt/homebrew visible in Finder >open /opt and then drag homebrew folder to left area in Finder 2. in IDEA choose the right path /opt/homebrew/Cellar/openjdk/17.0.1/libexec/openjdk.jdk/Contents/Home.Beaming
You saved me a livetime, thanksCheekbone
For Linux: /home/linuxbrew/.linuxbrew/Cellar/openjdk/17.0.2/libexecRedistrict
This is the solution for Mac. One thing that tripped me up though was setting this in Build > Compiler > Scala Compiler > Scala Compiler Server settings Make sure you set it in Build Tools either sbt or gradle settings if you are running the commands from IDE.Marlinmarline
R
11

This error occurs because if you choosing the path deep in JDK or JRE. The exact path that should be chosen is in my case 64 bit

C:\Program Files\Java\jdk1.8.0_91

if 32 bit

C:\Program Files (86)\Java\jdk1.8.0_91

Rosabelle answered 10/5, 2016 at 6:58 Comment(1)
For some odd reasons it works only if you install in one of the two paths mention by @Koushal Deva, I believe is a limitation of IntelliJNeurogram
B
4

May be your jdk is in /usr/lib/jvm/. This variant for linux.

Belford answered 15/9, 2016 at 13:31 Comment(0)
B
3

I had \bin as part of the path. Up one level of the selected directory worked for me.

Blastosphere answered 21/2, 2020 at 23:27 Comment(1)
This worked to me. You must put the path without the "bin" folder.Crier
G
2

I had the same issue. But I figured it out by choosing this path:

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. In my case, I downloaded the JDK1.8.0_60 version.

To resume the path:

C:\Program Files\java\jdk1.8.0_60

After you are done with it, you can click on the button next. Then you select the create project from templates. This will create a java application with a main() method. After it, you click next to create the name of you project.

I hope this helps you.

Gunthar answered 4/10, 2015 at 19:27 Comment(0)
I
2

One thing we should note: the jdk should be installed on C: drive.

I had JDK installed on my D: drive like this:

D:\Program Files\Java\jdk1.8.0_101

And it would still give me the same error. For some reason Java should be installed on C: drive.

Iotacism answered 4/6, 2017 at 1:26 Comment(1)
Mine is installed on my e:\drive and I am getting the same error.Berserker
M
2

for me ,with JDK11 and IntelliJ 2016.3 , I kept getting the same message so I decided to uninstall JDK11 and installed JDK8 instead and it immediately worked!

Mcavoy answered 27/11, 2018 at 18:20 Comment(0)
D
1

I ended up needing to replace 2017 with 2019, and everything worked fine. /shrug... no other suggestions here worked for me.

Darrin answered 21/7, 2019 at 1:26 Comment(0)
F
0

It got this error because I had managed to clobber jdk1.8.0_60 with the jre!

Flamingo answered 25/1, 2016 at 22:52 Comment(0)
G
0

In case you missed the configuration at the Project Structure(File -> Project Structure), just reconfigure it like below:

For Java enter image description here

For Android enter image description here

Enjoy coding J

Girt answered 24/6, 2018 at 5:43 Comment(0)
U
0

I had the same problem. The solution was to update IntelliJ to the newest version.

Unrequited answered 8/12, 2020 at 10:3 Comment(0)
A
0

Although JDK version 8 can be added into IntelliJ IDEA version 2017.2.6, I couldn't add JDK version 11.0.14 into and got the same error. Because of this, I downloaded new version of IntelliJ IDEA version (2021.3.2) and I could add JDK 11.0.14 into IntelliJ easily without any error. Using newer release of IntelliJ than JDK release can be reasonable recommendation for people who meet this kind of problems.

Altar answered 10/3, 2022 at 19:49 Comment(0)
A
0

upgrade to recent version of intellij work for me

Accoucheur answered 6/6, 2022 at 12:36 Comment(0)
D
0

If you are in ubuntu, i found the solution to your problem.If you are in mac, i thing is similar.

The thing is that firstly you must install the jdk and jre.

I have it in my /usr/lib/jvm

Then, after that, you must puth the variable $JAVA_HOME in your $PATH in the ~/.bashrc file at the end. But i found that after adding my jre and my jdk, my IDE didn't detect my jdk. So what i do to solve this in my IDE was:

In your command line:

nano ~/.bashrc

export JAVA_HOME='/usr/lib/jvm/<your-path>'
export PATH=$PATH:$JAVA_HOME/bin
source ~/.bashrc

If no problem was detected and all is fine, just do

java --version

If is detected, next, go to the other step:

=> Open your IDE. In this step, if your IDE doesn't recognize java version or SDK (as in my case), do the following

javac --version

This is where i solved the problem, becouse it looked like i didn't have javac, so I solved it with:

sudo apt install openjdk-<version>-jdk-headless

=> Then open your IDE and select the SDK you have just installed. Its like the IDE doesn't recognize de previus jdks.

Dak answered 10/3, 2023 at 14:3 Comment(0)
S
-1

For Windows, apparently the JDK has to be under C:\Program Files.

This does not work:

C:\dev\Java\jdk1.8.0_191     

This works:

C:\Program Files\Java\jdk1.8.0_191     

(I'm using IntelliJ IDEA Ultimate 2018.2.4.)

Sakmar answered 20/11, 2018 at 10:56 Comment(1)
This is not accurate.Savannasavannah

© 2022 - 2024 — McMap. All rights reserved.