Setting JAVA_HOME for intelliJ?

69,557

Solution 1

I use IDEA_JDK for this purpose (on linux).

I believe it is STUDIO_JDK for android studio.

For more information on this and other jetbrains IDE's, see https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

Solution 2

In IntelliJ you can specify which SDK to use at project level. go to "File" --> "Project Structure" --> SDKs (list on the left) and you can add/remove paths to different SDKs

Other solution: If you use Windows then I think you can specify JAVA_HOME as system property just for IntelliJ. If you use Linux the solution is similar.

Solution 3

The other answers will not work for 64bit versions. Jetbrains have actually documented this quite well. From https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under:

Java 8

Please be aware that Java 8 is required to run IntelliJ IDEA starting from version 16 on all the supported platforms. It also applies to the lightweight IDEs released from the same branch (144+).

Windows

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.

To run the IDE in 64-bit mode you will need to download and install 64-bit JDK (not JRE) distribution and install it yourself. IDE will find and use it from the registry when you run the 64-bit .exe file (available only for IntelliJ IDEA right now, other products can use the .bat file to run in 64-bit mode).

<product>.exe uses this JDK search sequence:

  • IDEA_JDK / PHPSTORM_JDK / WEBIDE_JDK / PYCHARM_JDK / RUBYMINE_JDK / CLION_JDK / DATAGRIP_JDK environment variable (depends on the product, WEBIDE_JDK applies to both WebStorm and PhpStorm before version 2016.1)
  • ..\jre directory
  • system Registry
  • JDK_HOME environment variable
  • JAVA_HOME environment variable

idea64.exe uses this JDK search sequence:

  • IDEA_JDK_64 environment variable
  • ..\jre64 directory
  • system Registry
  • JDK_HOME environment variable
  • JAVA_HOME environment variable

It’s also possible to start the IDE with .bat file located in the bin directory, it uses the following JDK search sequence:

  • IDEA_JDK / PHPSTORM_JDK / WEBIDE_JDK / PYCHARM_JDK / RUBYMINE_JDK / CLION_JDK / DATAGRIP_JDK environment variable (depends on the product)
  • ..\jre directory
  • JDK_HOME environment variable
  • JAVA_HOME environment variable

Environment variable must point to the JDK installation home directory, for example:

c:\Program Files (x86)\Java\jdk1.8.0_66

The actual JDK version used by the IDE can be verified in Help | About dialog (open any project to access the menu).

Define IDEA_JDK / PHPSTORM_JDK / WEBIDE_JDK / PYCHARM_JDK / RUBYMINE_JDK / CLION_JDK / DATAGRIP_JDK variable depending on the product to override the default version from IDE_HOME\jre.

Use Rapid Environment Editor to add/edit the variables, it will detect incorrect paths.

Linux

Starting from IntelliJ IDEA 16 and the most recent versions of the lightweight IDEs, we are bundling custom JRE with Linux distributions, just like we've been doing for Mac. Our custom JRE is based on OpenJDK and includes the most up to date fixes to provide better user experience on Linux (like font rendering improvements and HiDPI support).

Boot JDK path is stored in the .jdk file located in the config folder. It can be modified either via the Change IDE boot JDK action or by manually editing .jdk file (if you can't start the IDE to change it via an action). It's recommended to use the bundled JRE (if available). In case you have any issues with the bundled version, you can switch to the latest version of Oracle JDK or OpenJDK available for your system (OpenJDK 1.6 is not supported, please use 1.7 or later versions, JDK 1.8 is recommended and older Java versions are not supported starting from IntelliJ IDEA 16).

Check bin/.sh file for the JDK search order, it's similar to Windows in terms of the environment variable names. It's a legacy way to adjust the boot jdk, use it for older product versions. Consider using .jdk file instead (see above), so that your modifications can survive IDE updates/re-installation.

Check this answer if you need to install the JDK manually on Linux. If you have problems with ugly fonts, please see this thread comments for the tips.

Help | About will show the actual JDK version.

Mac OS X

Our latest IDE versions come with the bundled custom JDK 8 which contains the fixes for most known OpenJDK bugs. Should you need to use a different Java version, please refer to https://blog.jetbrains.com/idea/2015/05/intellij-idea-14-1-4-eap-141-1192-is-available/.

If you override IDE JDK version, its path is stored in .jdk file located in the config folder (idea.jdk for IntelliJ IDEA, pycharm.jdk for PyCharm, etc). Delete this file or change the path inside the file manually in case IDE no longer starts and you can't change it via the menu. If IDE doesn't start and this file doesn't exist, create it manually and specify Java path to use (Java home location), for example: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk

Share:
69,557
EJTH
Author by

EJTH

Updated on December 31, 2021

Comments

  • EJTH
    EJTH over 2 years

    So i decided to try the beta of android studio today, but it refuses to run on my 32-bit JRE. I can download the 64-bit JRE, but im not interested in it being my default JRE for various reasons (my current 32-bit eclipse IDE, Processing IDE and Minecraft doesn't like 64-bit to my experiences), and i think that swithing java_home dir all the time will be cumbersome.

    So does intelliJ have some way of setting an alternative JAVA_HOME dir like eclipse does in its ini?