How do I change the IntelliJ IDEA default JDK?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
IntelliJ IDEA, a popular Integrated Development Environment (IDE) for Java and many other programming languages, requires a Java Development Kit (JDK) to run and compile Java applications. By default, IntelliJ may use a bundled JDK version, but you might need to change the JDK version based on the requirements of your project or to use features available in a different JDK version.
Understanding JDK in IntelliJ IDEA
IntelliJ IDEA can configure JDKs at two levels - globally and per project. The global JDK affects all projects where a project-specific JDK is not defined. Changing the JDK at the project level allows you to configure a JDK specific for that project without altering other projects or global settings.
Changing the Global JDK Settings
To change the default JDK that IntelliJ uses globally, follow these steps:
- Open IntelliJ IDEA and navigate to the main menu.
- Click on
File > Project Structure > SDKs. - In the SDKs section, you will see a list of all configured SDKs in your IntelliJ. If the JDK you want to use is not listed, you will need to add it.
- To add a new JDK, click on the
+icon and selectJDK. Then, navigate to the directory where the JDK is installed on your computer and select it. IntelliJ will validate the JDK and add it to the list. - Once added, you can select it for any project or set it as the default SDK by using it in project settings.
Changing the JDK for a Specific Project
If you only need to change the JDK for a single project, follow these steps:
- Open your project in IntelliJ IDEA.
- Navigate to
File > Project Structure > Project. - In the Project SDK section, you can select an existing SDK from the drop-down menu, or add a new one by following similar steps as adding a global SDK.
- After selecting or adding the new JDK, apply the changes. This will change the JDK used for compiling and running the application within that specific project.
Checking and Configuring JDK for Run/Debug Configurations
Each run/debug configuration in IntelliJ can also specify which JDK or JRE to use. This is particularly useful when testing application compatibility with different Java versions.
- Go to
Run > Edit Configurations. - Select a configuration on the left panel.
- Under the
Configurationtab, you can find the option to select the JRE. Adjust it according to your needs for testing or running the application.
Automating JDK Configuration with Project Files
IntelliJ IDEA allows you to specify SDK settings in the project’s .idea folder, which can be particularly useful for maintaining consistent environment settings across multiple development environments. This is done through the misc.xml file where you can specify the project-level JDK.
Summary Table
Below is a summary of the key points discussed:
| Action | Path or Setting | Description |
| Adding a new Global JDK | File > Project Structure > SDKs | Add and select new JDK installations globally. |
| Changing Project JDK | File > Project Structure > Project | Change or select the JDK for the specific project. |
| Configuring Run Configurations | Run > Edit Configurations | Set specific JDK or JRE for different run configurations. |
| Automating SDK Settings | .idea/misc.xml | Specify JDK settings in project files for consistency across setups. |
Conclusion
Changing the JDK in IntelliJ IDEA is a straightforward process that can be done either globally or on a per-project basis. It allows developers to effectively manage different Java version requirements across various projects, enhancing productivity and ensuring compatibility. Always remember that updating to a newer JDK can provide better performance and more features, but it might also lead to compatibility issues with older applications, so it's important to test thoroughly after changes are made.

