Posted In: Linux, OS

How to install Oracle JDK 8 on CentOS

I am currently setting up my own CentOS VPS on Bluehost. I am going to write Rest Services using Spring Boot. To start I need to install Oracle/Sun JDK 1.8
This article is how to install JDK on Linux VPS or dedicated server.

Steps

1. Download JDK RPM. You can either use WGET or just copy it to your home directory if you already have RPM
RPM – It is package manager for Linux
2. Install using YUM command
YUM (Yellowdog Updater Modified) is an open source command-line as well as graphical based package management tool for RPM (RedHat Package Manager) based Linux systems.
3. Verify installation
4. Add JAVA_HOME to environment

1. Download RPM

wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.rpm

2. Install using YUM command

yum localinstall jdk-8u121-linux-x64.rpm

3. Verify installation

#cd /usr/java/jdk1.8.0_121/bin
#java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

4. Add JAVA_HOME to environment

Once we add to environment. JAVA_HOME will be available to all users

#vi /etc/environment
press i to insert (This is vi command)
Add following line 
JAVA_HOME="/usr/java/jdk1.8.0_121/"
press wq to write and save file

Logout and login again to check

#echo $JAVA_HOME
/usr/java/jdk1.8.0_121/

5. Add JAVA_HOME to .bash_profile

Some articles have recommended adding JAVA_HOME to .bash_profile. On my server only environment step was enough

#vi /home/javausecase/.bash_profile
press i to insert (This is vi command)
Add following line 
export JAVA_HOME=/usr/java/jdk1.8.0_121/
export JRE_HOME=/usr/java/jdk1.8.0_121/jre/
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

6. In case you have multiple JDKs installed, you can set default using alternatives command on CentOS

javausecase@server.javausecase.com [/]# alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk1.8.0_121/jre/bin/java

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

Tags: ,

by , on March 26th, 2017

  • Categories