It's due to IntelliJ IDEA need fixed installation of JDK, it have to be one of the following location:
Remark: After you installed JDK in the location, you have to set environment parameter point to the installed location. In my practice, I use the following commands in Terminal to update alternatives:
$sudo update-alternatives --install /usr/bin/javac javac /opt/java/bin/javac 1
$sudo update-alternatives --install /usr/bin/java java /opt/java/bin/java 1
where /opt/java/ is the location of my installed JDK.