How to jdk version in intellij
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- IntelliJ IDEA allows project-specific JDK configurations.
- The default JDK for a new project can be set in IntelliJ's settings.
- You can add multiple JDKs to IntelliJ IDEA and switch between them easily.
- Project SDKs are distinct from IntelliJ IDEA's own JVM, which runs the IDE.
- Ensure the JDK you select is compatible with your project's requirements.
Overview
Managing the Java Development Kit (JDK) version used by your projects in IntelliJ IDEA is crucial for ensuring compatibility, leveraging new language features, and avoiding runtime issues. IntelliJ IDEA provides a flexible system for configuring the JDK at both the project level and the module level, allowing you to tailor the development environment precisely to your needs.
Why Managing JDK Versions Matters
Java versions introduce new features, performance improvements, and sometimes deprecate older functionalities. Using the correct JDK ensures:
- Compatibility: Newer Java versions might not be backward compatible with older libraries or frameworks. Conversely, older JDKs cannot run code written for newer versions.
- Access to Features: To use features introduced in Java 8 (like lambdas), Java 11 (like `var`), Java 17 (LTS), or Java 21 (LTS), you must compile and run your code with the corresponding JDK version.
- Performance: Newer JDKs often come with significant performance enhancements and garbage collection improvements.
- Security: Keeping your JDK updated is vital for security patches.
Setting the JDK for a Project in IntelliJ IDEA
The primary way to manage your JDK is through the Project Structure settings. This allows you to define the SDK for the entire project or for individual modules within the project.
Step-by-Step Guide:
- Open Project Structure: Navigate to File > Project Structure... (or use the shortcut Ctrl+Alt+Shift+S on Windows/Linux, Cmd+; on macOS).
- Select 'Project': In the Project Structure dialog, select Project from the left-hand pane.
- Choose Project SDK: Under the 'Project' settings, you will see a dropdown menu labeled SDK. Click this dropdown.
- Select an Existing JDK: If the desired JDK is already configured in IntelliJ IDEA, it will appear in the list. Select it from the dropdown.
- Add a New JDK: If your desired JDK is not listed, click the Add SDK button (often represented by a '+' icon) and choose JDK. IntelliJ IDEA will then prompt you to locate the installation directory of the JDK on your system. Browse to the directory (e.g., `/usr/lib/jvm/java-17-openjdk-amd64` on Linux, `C:\Program Files\Java\jdk-17` on Windows, or `/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home` on macOS) and click 'OK'. IntelliJ IDEA will detect and add it to its list of available SDKs.
- Confirm Changes: Once you have selected or added the correct JDK, click Apply and then OK to close the Project Structure dialog.
Setting the JDK for a Module
Sometimes, you might have a multi-module project where different modules require different JDK versions. You can configure this within the same Project Structure dialog:
- Navigate to File > Project Structure...
- Select Modules from the left-hand pane.
- Choose the specific module you want to configure from the list.
- Under the Dependencies tab for that module, you can set the Module SDK. This setting overrides the project-level SDK for this particular module.
- As with the project SDK, you can select from existing JDKs or add new ones using the '+' button.
IntelliJ IDEA's JDK vs. Project JDK
It's important to distinguish between the JDK that IntelliJ IDEA itself uses to run (the IDE's JVM) and the JDK configured for your project. You can check and change the IDE's JDK in IntelliJ IDEA's settings (File > Settings > Build, Execution, Deployment > Build Tools > Gradle/Maven for build tools, or check the VM options for the IDE itself). However, for day-to-day development, the Project Structure settings are what you'll use most often to define the JDK for your code compilation and execution.
Common Issues and Troubleshooting
- JDK not found: Ensure the JDK is correctly installed and that you are pointing IntelliJ IDEA to the root directory of the JDK installation, not a subfolder.
- Compatibility errors: If you encounter errors related to language features or APIs, double-check that your Project SDK version matches the Java version your code is intended for. For example, if you're using Java 17 features, ensure your Project SDK is set to a JDK 17 or higher.
- Build tool issues: If you're using Maven or Gradle, make sure the JDK configured for the build tool within IntelliJ IDEA (in Settings) aligns with your project's JDK. Sometimes, Maven/Gradle might pick up a different default JDK than what you've set in Project Structure.
Best Practices
- Use LTS versions: For long-term projects, consider using Long-Term Support (LTS) versions of Java, such as Java 8, 11, 17, or 21, for stability and continued support.
- Keep IDE updated: Regularly update IntelliJ IDEA to ensure compatibility with the latest JDKs and features.
- Version Control: While IntelliJ IDEA manages JDK settings locally, consider using build tool configurations (like `maven-compiler-plugin` or Gradle's `java` block) to specify the Java version required by your project in a way that's portable across different development environments and CI/CD pipelines.
By correctly configuring your JDK in IntelliJ IDEA, you ensure a smooth and efficient development workflow, allowing you to focus on writing code rather than troubleshooting environment issues.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- SDKs: IntelliJ IDEA Helpfair-use
- JDK Projects - OpenJDKCC0-1.0
- Java SE Documentation | Oraclefair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.