How do I downgrade JDK?
You have two options ahead of you:
- You can uninstall JDK-16.0.2, then install OpenJDK 11 and have just that implementation on your system
- You can install OpenJDK 11 and use
update-alternatives
to specify which version you want to be treated as default
This answer will focus on the second option, though you can modify it to work for the first.
- Open a Terminal (if one is not already open) or SSH into the server you're installing Java onto
- Install the default Java runtime. For Ubuntu 20.04, this is version 11.0.11:
If you want to be absolutely certain of the version, you can also specify the version:sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
- Install the default Java Development Kit:
sudo apt install default-jdk
- Confirm the versions:
This should give you something like:java -version
Also check the compiler:openjdk version "11.0.11" OpenJDK Runtime Environment (build 11.0.11+9-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Ubuntu-3ubuntu1, mixed mode, sharing)
Which will give you something like:javac -version
javac 11.0.11
- Set version 11 as the default for the system:
This will give you an output similar to:sudo update-alternatives --config java
You can also do this for the compiler with:There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status -------------------------------------------------------------------------------- 0 /usr/lib/jvm/java-16-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-16-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1091 manual mode Press <enter> to keep the current choice[*], or type selection number:
sudo update-alternatives --config javac
- Confirm your
JAVA_HOME
variable is correct:
Note: Feel free to use any text editor that you prefer. The use ofsudo vi /etc/environment
vi
here is more a force of habit than an endorsement. Locate theJAVA_HOME
variable and ensure it's set correctly:
Reload your sources:JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Verify the variable is set:source /etc/environment
You should see:echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64
That's all there is to it 👍🏻