Install and Upgrade Java Version on CentOs ,Red Hat and Fedora Linux

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 also the multiple version 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 installed or upgrade the java version.

Downloading Latest Java Version 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 under the GPL License.

Run below command to download and extract the downloaded file  .

Linux x64 Java Development Kit 

# cd /tmp
# wget
# 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 accept header and license use the above syntax for download.

Installation of Latest Java

Update Java

Now go to the java extracted folder through the below command and install or switch to java version through alternatives command. This is the best way to install or switch the java version to other. When we run the alternatives –config java , the command output will show different java programs which provide java, We need to choose or select command.Here we have selected /opt/jdk-16.0.1/bin/java .Follow 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
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 updated Java 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)

About 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!

Have any Question or Comment?

2 comments on “Install and Upgrade Java Version on CentOs ,Red Hat and Fedora Linux


Thank you, it helps !

Vihag Gupta

Great! Thanks a ton!


Leave a Reply

Your email address will not be published. Required fields are marked *