Explain Codes LogoExplain Codes Logo

How to Set IntelliJ IDEA Project SDK

java
intellij-idea
jdk-configuration
project-sdk
Anton ShumikhinbyAnton Shumikhin·Feb 21, 2025
TLDR

Setting the IntelliJ Project SDK is quite straightforward. Go to File > Project Structure > Project. In the Project SDK dropdown, you can either choose an existing SDK or add a new one via the Add SDK button. Confirm the JDK version matches your project's needs. Click Apply and OK to update the settings.

Step-by-Step JDK Configuration

Discovering the JDK home directory

Every star programmer knows that IntelliJ IDEA requires the exact path to the JDK home directory. Here's where you may uncover them, adventurer!

  • Windows: "C:\Program Files\Java\jdk-<sneaky_version_number>"
  • macOS: "/Library/Java/JavaVirtualMachines/jdk-<mystery_version_number>.jdk/Contents/Home"
  • Linux: "/usr/lib/jvm/java-<invisible_version_number>-openjdk"

Remember to replace <mystery_version_number> with the real version number of your hidden JDK treasure.

Fresh Projects? Fresh SDK configuration!

Creating a new project in IntelliJ is as exciting as landing on an unexplored planet! IntelliJ will ask for the Project SDK right in the first step — it's the air your project needs to breathe. If there's no breathable air (no SDK set up), hit the Add SDK button and navigate to that JDK home directory.

Adapting SDK for those vintage projects

Working with existing projects sometimes feels like being an archaeologist discovering ancient ruins. To examine these ruins with modern-day tools (change the JDK for such projects), use the shortcut ctrl+alt+shift+S to bring the project structure back to life. Navigate to the SDK section where you can renovate the environment with a modern or an invaluable antique JDK version (your choice!)

Just when you thought setting up the JDK is smooth sailing, there could be a couple of booby traps!

  • Wrong JDK version: Ensure the JDK version is the right key to your specific treasure chest (project).
  • Incorrect path: Make sure you're on the right path to the JDK home directory. There's no treasure at the end of a wrong path!
  • Environment variables: On some exotic islands (systems), you might need to set environment variables to point to the JDK.

Advanced Techniques

Walking the plank - Switching SDKs

Working with a crew of developers often on different JDKs? No worries! IntelliJ IDEA lets you manage multiple SDKs and switch between them based on your current task.

Automagic SDK Management

Power users can cast a spell by automating SDK management through the Project SDK API provided by IntelliJ Platform SDK. This is potent magic and should be ventured cautiously.

Adventures in Virtual Environments and Containers

Venturing into virtual environments or containers like Docker? Your JDK setup needs to provide food and water (runtime and SDK) for the container. Configure the project settings to match the container's environment to ensure a consistent development voyage across different ships (machines).