Java is the popular programming language in the world. It is owned by Oracle and used to build different kinds of applications. Also, Java software platform allows you to run Java applications and applets.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Java Software package queries.
In this context, we shall look into how to install Java on CentOS 7 using different methods.
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.
Before proceeding with this Installation procedure, ensure that you are using a user account with sudo privileges.
Java is distributed in three different editions, Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). This guide covers the Java SE (Standard Edition) edition.
Java has the following three editions:
Here, 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.
How to Install OpenJDK on CentOS ?
OpenJDK installation is simple and straightforward. By default, OpenJDK implementation of the Java Platform is the default Java development and runtime in CentOS 7.
Now, we will Install OpenJDK 11 JDK in the next step.
You can install it by running below command:
$ sudo yum install java-11-openjdk-devel
Now you can verify the installation by typing:
$ java -version
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)
How to 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.
How to 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
How to 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
How to Install Oracle Java on CentOS?
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, ensure that you replace with your specific version of Java.
How to Set up default Java Version on CentOS ?
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:
$ java -version
To change the default version use the alternatives system command as below:
$ sudo alternatives --config java
There are 2 programs which provide 'java'.
1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-18.104.22.168-0.el7_6.x86_64/bin/java)
*+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-22.214.171.124.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.
How to Uninstall Java from CentOS ?
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
This article covers how to install and manage multiple Java versions on CentOS 7 system. At the end you also learned how to set default Java version. Java is used for developing anything from lightweight mobile to desktop applications.
How to Install Java 8 on CentOS ?
1. Update the system before installing any new programs:
$ yum -y update
2. Install Java 8:
$ yum install java-1.8.0-openjdk
3. Verify Java is Installed
$ java -version