How to downgrade Java version in Mac system?

1.9k views Asked by At

I am using mac and inside mac using Android Stuidio, I have done all setup and now My project requires Java version 11 but currently I have Java version 17.

I have checked Java version with this command as : java --version and it gives me below output in terminal :

openjdk 17.0.6 2023-01-17 OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) OpenJDK 64-Bit Server VM (build 17.0.6+0-17.0.6b829.9-10027231, mixed mode)

How can I change this to:

openjdk 11.0.20.1 2023-08-24

I have tried explain my issue and expecting the solution for that.

1

There are 1 answers

0
Basil Bourque On

Install another JDK

You can install multiple JDKs on your Mac. You can have a JDK for Java 11 as well as a JDK for Java 17. And perhaps you might want another JDK for the new Java 21 that arrived yesterday. These can all live together, side-by-side.

Each JDK is just a folder full of files. You can add JDKs, and delete JDKs, at will.

The environment variable JAVA_HOME is a hint various software as to which JDK you would like to use by default.

You might find a feature within Android Studio to install another JDK. (At least the sibling product, IntelliJ, offers such a feature.)

Configure project

Within your project in Android Studio, you need to set some settings to indicate which of your installed JDKs should be used for compiling, building, and executing your app. See the Android Studio documentation.

SDKMAN!

Personally, I find it easiest to install SDKMAN!, a bunch of shell scripts that manage installing/uninstalling JDKs (and other such kits). This works well on macOS.

SDKMAN! is designed to be utterly simple to use.

On a console such as Terminal.app, execute:

  • sdk list java
    See a list of all JDK products from vendors who chose to submit their data to the SDKMAN! database. From this list you copy the exact name of the JDK product you want to install. The list of products indicates any you have currently installed.
  • sdk install java product_name_goes_here
    Install the JDK product of your choosing. Takes a moment to download and install. At the end, SDKMAN! prompts you to specify whether you want to make this newly installed JDK the default.
  • sdk uninstall java product_name_goes_here
    Removes that particular JDK product from your Mac.