Explain Codes LogoExplain Codes Logo

How do I change the IntelliJ IDEA default JDK?

java
intellij-idea
jdk
java-compiler
Anton ShumikhinbyAnton Shumikhin·Sep 22, 2024
TLDR

To tweak the default JDK in IntelliJ IDEA, adhere to these quick steps:

  1. Head to: File > New Projects Setup > Structure... and select the Project tab.
  2. Under Project SDK, select your desired JDK or Add New... if your JDK isn't already listed.

For JDK 11:

File > Structure... > Project Settings > Project SDK > [Pick JDK 11 or Add...]

This one-time setup allows all your forthcoming projects to adopt the selected JDK, saving you from repetitive JDK changes for individual projects.

The settings walkthrough: easy steps

Before 2017.3 - Slight difference

If you're running earlier versions of IntelliJ IDEA (prior to 2017.3), the procedure slightly varies:

  • Go through File > Other Settings > Template Project Structure… for modifying both Project SDK and Project Language Level.

Stay updated for unhindered operations

To enjoy the latest features and for a seamless JDK switch, keep your IntelliJ IDEA updated. This ensures consistency between your version and the walkthrough here.

The swift blade of IntelliJ - Keyboard shortcuts

Hotkey wizards, use Ctrl+Alt+Shift+S. This power combo for Project Structure dialog grants quick access to JDK modification settings.

Language level synchronisation - Crucial coupling

To enjoy optimal performance, ensure your Project Language Level aligns with the JDK version. For instance, for Java 8, choose 8 - Lambdas, type annotations etc. and taste the future of syntax!

Checking your backstage worker - The Compiler

After adjusting the JDK, align your Java compiler settings with it. This ensures effective utilisation of the updated JDK's features and improvements.

Maven or Gradle projects - Special consideration

For projects managed by Maven or Gradle, indicate the JDK in the pom.xml or respective build file. This helps in keeping the language level consistent and avoiding unnecessary prompts.

Additional setup - New JDK installation

In case you need a JDK version not listed in IntelliJ IDEA's SDK Manager:

  1. Head to the official Java website or an OpenJDK provider, and download the required version.
  2. Unpack the JDK to your preferred directory.
  3. Use IntelliJ IDEA's Guided Setup to register the newly installed JDK.
# Pro tip: Make the IDE do the heavy lifting! 💪 # Using Guided Setup - less fuss, less muss. Neat! ✨

Troubleshooting tips - Overcoming hiccups

JDK doesn't show up?

Ensure the JDK is correctly added to IntelliJ IDEA by re-navigating to Project Structure > SDKs to manually add the JDK path, if not listed.

// Meanwhile, the poor JDK: "But I'm already here!" 🙁

Issues with project imports?

Check your project's build tool configurations and IntelliJ IDEA system settings to ensure perfect JDK harmony.

// JDK to project: "Trust me, I'm an engineer!" 💼

In need of visual aids?

Screenshots shared in existing answers can be a great assistance, serving as a virtual mentor!