Java is the popular programming language in the world. It is owned by Oracle and used to build different kinds of applications. We will install various versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK). Also, we will install OpenJDK from official packages from Oracle. In this tutorial, we are going to install Java on CentOS 7 using different methods.
Before you start, you should logged in on Debian 9 server using non-root user account with sudo privileges.
Install Java on CentOS 7
Java is distributed in three different editions, Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). This tutorial covers the Java SE (Standard Edition) edition.
Java has the following three editions:
There are three different editions of Java as given below:
- Standard Edition(SE)
- Micro Edition(ME)
- Enterprize Edition(EE)
In this tutorial we will covers the Standard Edition(SE). Also there are two implementation available for Java, One is Oracle Java and OpenJDK Java. There is no more difference in Oracle Java and OpenJDK Java as Oracle Java provides some additional enterprise features.
OpenJDK installation is simple and straightforward. By defalt, OpenJDK implementation of the Java Platform is the default Java development and runtime in CentOS 7.
Install OpenJDK 11 JDK
Currently, latest LTS version of Java is is OpenJDK 11. You can install it by run below command:
sudo yum install java-11-openjdk-devel
Now you can verify the installation by typing:
It should output as given below:
openjdk version "11.0.3" 2019-04-16 LTS OpenJDK Runtime Environment 18.9 (build 11.0.3+7-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.3+7-LTS, mixed mode, sharing)
Install OpenJDK 11 JRE
If you want to install OpenJDK 11 JRE you can do it by simply running below command:
sudo yum install java-11-openjdk
JRE is a subset JDK and if you already installed the JDK package you do not need to install this one.
Install OpenJDK 8 JDK
Java 8 is mostly used version of Java. If your applications required Java 8 then you can install on your CentOS 7 system by executing below command:
sudo yum install java-1.8.0-openjdk-devel
Install OpenJDK 8 JRE
If you required only OpenJDK 8 JRE the you can install it just by running below command:
sudo yum install java-1.8.0-openjdk
Install Oracle Java
Oracle packages are available to download only from their official website. Oracle provides license permits only non-commercial use, for personal use and development use only. So before going to install it read the Oracle JDK License.
Download the Oracle Java .rpm packages from the Java SE Official downloads page. First you need to register on the Oracle site to download.
sudo yum localinstall jre--linux-x64.rpm
In above command replace the with your specific version of Java.
Setting up default Java Version
If your system have multiple version of Java then you can set default version as per your choice.
First, check the current default version by typing:
To change the default version use the
alternatives system command as below:
sudo alternatives --config java
Output There are 2 programs which provide 'java'. Selection Command 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-126.96.36.199-0.el7_6.x86_64/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-188.8.131.52.b04-0.el7_6.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number:
You can see list of all installed Java versions. Select appropriate selection number to set as default version.
You can uninstall the Java package same as other packages. For example, if you want to uninstall the
java-1.8.0-openjdk package simply run:
sudo yum remove java-1.8.0-openjdk
You have learned How to install and manage multiple Java versions on CentOS 7 system. At the end you also learned how to set default Java version.
If you have any queries regarding this tutorial feel free to comment below.