CentOSLinuxTutorials

How To Install Java JDK 8 on CentOS 7

Install Java JDK 8 on CentOS 7

In this tutorial, we will show you how to install Java JDK 8 on CentOS 7. Java Development Kit (JDK) 8 is a pivotal technology in the world of Java programming, offering the tools needed to develop and run Java applications. This article aims to guide CentOS 7 users through the installation process of Java JDK 8, covering both OpenJDK and Oracle JDK installations.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Java on CentOS 7.

Prerequisites

  • A server running one of the following operating systems: CentOS 7.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Java JDK 8 on CentOS 7

Step 1. Preparing the System.

Begin by updating your system’s package index to ensure you have access to the latest versions of software and dependencies:

sudo yum update

Next, enable the EPEL repository to ensure you have access to additional packages needed for the installation:

sudo yum install epel-release

Step 2. First, remove the Java 1.6 or 1.7 that have been installed already, you can uninstall them using the following commands.

yum remove java-1.6.0-openjdk
yum remove java-1.7.0-openjdk

Step 3. Downloading the latest Java archive.

At the time of writing this tutorial, the latest Java JDK version was JDK 8u45. First, let us download the latest Java SE Development Kit 8 release from its official download page or use the following commands to download from the shell:

cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz"
tar xzf jdk-8u45-linux-x64.tar.gz

Step 4. Install JAVA using alternatives.

After extracting the archive file use the alternatives command to install it. alternatives command is available in chkconfig package:

cd /opt/jdk1.8.0_45/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 2
alternatives --config java
There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /opt/jdk1.7.0_71/bin/java
 + 2           /opt/jdk1.8.0_25/bin/java
   3           /opt/jdk1.8.0_45/bin/java

Enter to keep the current selection[+], or type selection number: 3

At this point, JAVA 8 (JDK 8u45) has been successfully installed on your system. We also recommend to set up the javac and jar commands path using alternatives:

alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_45/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_45/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_45/bin/jar
alternatives --set javac /opt/jdk1.8.0_45/bin/javac

Step 5. Checking installed Java version.

root@idroot.us ~# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Step 6. Set up global environment variables.

We can easily set the environment variables using the export command as shown below:

Setup JAVA_HOME Variable:

export JAVA_HOME=/opt/jdk1.8.0_45

Setup JRE_HOME Variable:

export JRE_HOME=/opt/jdk1.8.0_45/jre

Setup PATH Variable:

export PATH=$PATH:/opt/jdk1.8.0_45/bin:/opt/jdk1.8.0_45/jre/bin

Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing Oracle Java on the CentOS 7 system. For additional help or useful information, we recommend you check the official Java website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button