IntelliJ IDEA
JDK
Java Development Kit
Programming
Software Configuration

How do I change the IntelliJ IDEA default JDK?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

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:

  1. Open IntelliJ IDEA and navigate to the main menu.
  2. Click on File > Project Structure > SDKs.
  3. 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.
  4. To add a new JDK, click on the + icon and select JDK. 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.
  5. 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:

  1. Open your project in IntelliJ IDEA.
  2. Navigate to File > Project Structure > Project.
  3. 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.
  4. 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.

  1. Go to Run > Edit Configurations.
  2. Select a configuration on the left panel.
  3. Under the Configuration tab, 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:

ActionPath or SettingDescription
Adding a new Global JDKFile > Project Structure > SDKsAdd and select new JDK installations globally.
Changing Project JDKFile > Project Structure > ProjectChange or select the JDK for the specific project.
Configuring Run ConfigurationsRun > Edit ConfigurationsSet specific JDK or JRE for different run configurations.
Automating SDK Settings.idea/misc.xmlSpecify 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.


Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.