50

After installing Intellij Idea 14, with OracleJDK 1.8 u25 (64 bit) on my 14.04 Ubuntu system, I cannot configure the Java SDK to use any JDK. When I navigate to Module Settings->SDK and click configure SDK, the add button, and then select /usr/java/jdk1.8.0_25 in the dialog, I get an error popup stating that "The selected directory is not a valid home for JDK."

I've checked the contents of the directory, which contains a bin folder with both java and javac inside, a lib folder and a jre folder.

I've tried selecting each of those in turn, to no avail, which I expected.

Andrew Schade
  • 808
  • 1
  • 7
  • 14

4 Answers4

76

I had the same problem, in my case I wasn't able to select any of the "openjdk" directories under /usr/lib/jvm/, I solved with:

sudo apt-get install openjdk-8-jdk

When restarting intellij it will find the path to the jdk automatically.

Douy789
  • 1,015
  • 10
  • 16
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
26

For the ones who run into this problem even though you select the right directory under /usr/lib/jvm, there is something you should know : The directories under /usr/lib/jvm are created when your system installs the minimum set of java tools. But it doesn't mean you have the development files available. You need to install the development files :

sudo apt-get install java-1.8.0-openjdk-devel

After installing this package, try to select the directory again and it should work.

vdegenne
  • 12,272
  • 14
  • 80
  • 106
11

Evan Knowles posted a link to https://askubuntu.com/questions/130186/what-is-the-rationale-for-the-usr-directory. It provided me with the solution to the problem.

Instead of using the JDK at /usr/java/jdk1.8.0_25, I instead used the JDK at /usr/local/java/jdk1.8.0_25. The reasons that this works rather than the other are explained in detail within the link.

Community
  • 1
  • 1
Andrew Schade
  • 808
  • 1
  • 7
  • 14
3

I came across this error because I did not have JAVA_HOME set.

Adding export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 (for openjdk 11 in my case) and export PATH=$JAVA_HOME/bin:$PATH to my ~/.bashrc and then running source ~/.bashrc solved the problem for me.

Imran
  • 12,950
  • 8
  • 64
  • 79