how to change java version in intellij

Switch Java Version in IntelliJ: Easy Steps

By Daniel White
AD

Tired of accidentally using deprecated methods or incompatibility issues due to using the wrong Java version in IntelliJ? You're not alone. Here's a step-by-step guide on how to change the Java version in IntelliJ, ensuring your development experience is smooth and issue-free.

Before we dive into the process, let's understand why it's crucial to set the correct Java version. Different projects may require specific Java versions. Some features are only available in newer versions, while certain libraries may only support older ones. Setting the right Java version ensures your project is compatible and runs smoothly.

Changing Java SDK in IntelliJ

IntelliJ allows you to set a different Java SDK for each project, providing flexibility for multi-language projects. Let's explore how to change the Java version for your current project.

AD
How to Change the Java Version in an IntelliJ Project | Baeldung
How to Change the Java Version in an IntelliJ Project | Baeldung
a poster with the words inteluli idea and some type of information on it's side
a poster with the words inteluli idea and some type of information on it's side
7 Common Java Errors Beginners Make (And How to Fix Them) | Java Programming Tips
7 Common Java Errors Beginners Make (And How to Fix Them) | Java Programming Tips

Before proceeding, ensure you have the desired Java version installed on your system. You can download it from the official Oracle Java SE Development Kit page.

Locating the Project SDK

First, let's find where IntelliJ stores the Java SDK path for your project. IntelliJ doesn't directly use the system's Java version but the one specified in the project settings. Here's how to locate it:

a woman with long black hair sitting in front of a computer
a woman with long black hair sitting in front of a computer
How to Check Java Version in Command Prompt (Windows 11 & 10): Fix Common Java Command Error
How to Check Java Version in Command Prompt (Windows 11 & 10): Fix Common Java Command Error

1. Open your project in IntelliJ.

2. Click on the 'File' menu, then 'Project Structure'.

AD

3. In the left-hand pane, under the 'Platform Settings' section, click on 'SDKs'.

Modifying the Project SDK

Now that you've located the Java SDK path, let's modify it to use your desired Java version.

1. In the 'Project SDK' dropdown menu, select 'Edit'.

AD

2. Click on the ' Galeria' tab at the top of the dialog box.

3. Find and select the desired Java version from the list. If it's not listed, click on 'Add Local' at the bottom of the dialog box, browse to the JDK's 'bin' folder, and select the 'java.exe' or 'java' file.

4. Click 'OK' to apply the changes.

AD

5. If prompted with a warning about changing the project's SDK, click 'OK' to confirm.

That's it! You've successfully changed the Java version for your IntelliJ project. Now, let's ensure IntelliJ uses the new SDK for running and debugging your project.

Setting the Project SDK for Run/Debug Configurations

While changing the project SDK, IntelliJ automatically applies the new SDK for new run/debug configurations. However, if you've already created run/debug configurations before changing the SDK, they might still be using the old SDK. Here's how to update them:

Updating Run/Debug Configurations

You can update the SDK for each run/debug configuration individually or apply the project's SDK globally.

1. To update individual configurations, select the configuration in the dropdown menu (e.g., 'Edit Configurations...' for running 'MyApplication').

2. Click on the '/*' symbol next to the 'VM options' field, then select 'Use project SDK'.

3. If prompted, click 'OK' to confirm.

Or, to apply the project's SDK globally:

1. Click on the 'File' menu, then 'Settings' (or 'Preferences' on MacOS).

2. In the left-hand pane, under the 'Build, Execution, Deployment' section, click on 'Java Compiler'.

3. In the 'Java Compiler' settings, ensure 'Use project SDK' is selected under the 'Project' section.

4. Click 'Apply', then 'OK'.

Now, you can enjoy the benefits of using the desired Java version in your IntelliJ project. Always remember to set the correct Java version before starting a new project or migrating an existing one to ensure compatibility and smooth development.

Happy coding!

AD