When the server OS is installed on the server or system, most of the time java version is not updated or not installed on the operating system, and also sometimes we need to update or upgrade the Java version on the server. Earlier in our article, we had to install any version of Java on a freshly installed server. Now we are going to upgrade or update the Java version from the old Java version to the latest version. Here you can see the multiple versions of Java also installed on the server. Recently Java version 16 also launched.

Below is my Java version, I ran the command to check the java version java -version, Nowhere is the output of my command.

[root@server1]# java --version
openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Below are the steps to install or upgrade the Java version.

Downloading the Latest Java Version of Linux Binary

Here was the java launch recently update OpenJDK 16, so we have downloaded it on the server through the below command. You can find the latest version of java on the official site page. Oracle also provides the latest OpenJDK release at jdk.java.net under the GPL License.

Run below command to download and extract the downloaded file  .

Linux x64 Java Development Kit 

# cd /tmp
# wget https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_linux-x64_bin.tar.gz
# tar xzf openjdk-16.0.1_linux-x64_bin.tar.gz
# mv jdk-16.0.1 /opt


As we have earlier discussed in other articles that  –no-cookies and  –header options with curl or wget because Oracle does not give download unless we have not accepted their license or terms For accepting header and license use the above syntax for download.

Installation of the Latest Updated Version

Now go to the java extracted folder through the below command and install or switch to the java version through the alternatives command. This is the best way to install or switch the Java version to another. When we run the alternatives –config java, the command output will show different java programs which provide java, We need to choose or select a command. Here we have selected /opt/jdk-16.0.1/bin/java. Follow the below command to set up.

# cd /opt/jdk-16.0.1
# alternatives --install /usr/bin/java java /opt/jdk-16.0.1/bin/java 2
# alternatives --config java
upgrade java
Select Java Version

Now set the jar and javac path .

# alternatives --install /usr/bin/jar jar /opt/jdk-16.0.1/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk-16.0.1/bin/javac 2
# alternatives --set jar /opt/jdk-16.0.1/bin/jar
# alternatives --set javac /opt/jdk-16.0.1/bin/javac

Now set the Environment Variables path of Java,Jre  home variable  through below commands

# export JAVA_HOME=/opt/jdk-16.0.1/
# export JRE_HOME=/opt/jdk-16.0.1/jre

Check the updated Version :

[root@panel jdk-16.0.1]# java --version
openjdk 16.0.1 2021-04-20 
OpenJDK Runtime Environment (build 16.0.1+9-24)
OpenJDK 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

You can also refer steps to install java on linux based operating system Here

By Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks! Sachin G Follow me on LinkedIn and x formerly twitter