In this article, We are going to perform How to Download and Install Oracle JAVA 8 on CentOS 7 Manually or any cloud VM instance like Amazon EC2, Azure VM, Google Compute Engine with preinstalled CentOS 7.
Table of Contents
Introduction
Java is a set of software and specifications developed at Sun Microsystems. There are two tyes of Java Platforms are JDK (Java Development Kit) and JRE (Java Runtime Environment). Both are helpful for deploying applications on servers and debugging, JVM monitoring,developing.
Java 8 Features:
Java 8 provides following features,
- ForEach() method
- Functional interfaces
- Base64 Encode Decode
- Parallel array sorting
- Nashorn JavaScript Engine,
- Parallel Array Sorting
- Type and Repating Annotations
- java.lang and java.util Packages
To know more detailed features go through this link.
Prerequisites
- CentOS 7 with Minimal Installation
- SSH access with sudo privileges
To check CentOS version:
$ uname -a
OR
$ cat /etc/os-release
Output:
$ cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
Follow the below steps to Install Oracle Java 8 on CentOS 7 Manually using command line.
Step 1: Download Oracle Java 8
Generally Oracle will not allow to download directly without accepting their licences. We have to create one account in Oracle java website by your personal or official mail. After accepting licence download the application from browser to local machine.
This link takes you to the Oracle home website Oracel Java SRE.
Once you opened above link goto “JAVA SE Development Kit 8u231” section, click on “Accept License Agreement” Radio button and download “jdk-8u231-linux-x64.tar.gz” setup for CentOS 7
After downloading into local machine,using SCP/SFTP/FTP transfer the file from local machine to CentOS 7 Server.
Step 2: Copy downloaded Setup and Extract
Create a directory /opt/jdk.
$ sudo mkdir -p /opt/jdk
Copy the tar file from the directory copied from local machine to server to /opt/jdk folder and execute below command:
$ sudo cp -rf /home/sivasai/jdk-8u231-linux-x64.tar.gz /opt/jdk/
$ cd /opt/jdk/
$ sudo tar -zxf jdk-8u231-linux-x64.tar.gz
Now unarchived the file and check the content by long-list:
# ls
Output:
$ ls jdk1.8.0_231 jdk-8u231-linux-x64.tar.gz
Step 3: Install Oracle Java 8 on CentOS 7 with Alternatives
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_231/bin/java 100
update-alternatives: using /opt/jdk/jdk1.8.0_231/bin/java to provide /usr/bin/java (java) in auto mode
Note : Its not particularly o/p if you have installed open jdk before
Step 4: Verify Update Alternatives
$ sudo update-alternatives --display java
java - auto mode link best version is /opt/jdk/jdk1.8.0_231/bin/java link currently points to /opt/jdk/jdk1.8.0_231/bin/java link java is /usr/bin/java /opt/jdk/jdk1.8.0_231/bin/java - priority 100 /opt/jdk/jdk1.8.0_231/bin/javac - priority 100
$ sudo update-alternatives --config java
$ sudo update-alternatives --config java There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre/bin/java) 2 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java) 3 /opt/jdk/jdk1.8.0_231/bin/java Enter to keep the current selection[+], or type selection number: 3
Step 5: Setting the JAVA_HOME and JRE_HOME Environment Variables
$ sudo nano /etc/environment
JAVA_HOME=/opt/jdk/jdk1.8.0_231 JRE_HOME=/opt/jdk/jdk1.8.0_231/jre
$ source /etc/environment
$ echo $JAVA_HOME
/opt/jdk/jdk1.8.0_231
$ sudo yum update
Step 6: Verify Java Version
$ java -version
$ java -version java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
Conclusion
In this article, We have downloaded Oracle Java 8 from official site, installed using command line, configured JAVA_HOME and JRE_HOME, verified installed version.
How to Download and Install JAVA SE JDK 8 on Windows 10
How to Download and Install Oracle Java 8 on Ubuntu 18.04/16.04 Manually
How to Download and Install Oracle JAVA 11 on Ubuntu 18.04/16.04 LTS