How to Install Open JDK/Oracle JDK on CentOS 7 or RHEL 7

Java is used in most application today as their development base of their application. So, you need to install Java Development Kit (JDK). This guide will help you to install either Open JDK or Oracle JDK to your development environment on Redhat (RHEL 7) or CentOS 7.

Note: you can install multiple JDKs on single operating system.

Let’s start the tutorial.

First, you need to have wget package already installed. If not yet, do following to install it.

yum install -y wget

Install OpenJDK

In repository, there are several version of OpenJDK as followings:

java-1.8.0-openjdk.x86_64          # To execute java    # For compilation of Java. javac etc.. java-1.8.0-openjdk-headless.x86_64 # no audio/video. Just SE. E.g for embedded systems

To install it do following command.

yum install -y java-1.8.0-openjdk-headless.x86_64

Check Java version installed.

# java -versionopenjdk version "1.8.0_191 # OpenJDK

Install OracleJDK

Navigate to official OracleJDK site to get the latest version.

Following step will install OracleJDK. We will install OracleJDK 11.

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

Untar and extract the package.

tar -zxvf jdk-*mv jdk* /usr/

You must setup Java with the alternatives commands. Following commands will install the Java on your system.

update-alternatives --install /usr/bin/java java /usr/jdk-11.*/bin/java 2

Set the default java with following command.

alternatives --config java

If your system has multiple versions of Java installed, then the above command may provide you a list of Java installation.

There are 2 programs which provide 'java'.  Selection    Command-----------------------------------------------*+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-   2           /usr/jdk-11.0.3/bin/javaEnter to keep the current selection[+], or type selection number: 2

See also  Fix initscripts conflicts with redhat-release-server-7.4-18.el7.x86_64

Verify the installation.

# java --versionjava version "11.0.3" 2018-10-16 LTSJava(TM) SE Runtime Environment 18.9 (build 11.0.3+13-LTS)Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+13-LTS, mixed mode)

Set the Environment Variables.

The last part is the most important, so you can run Java-based application because you have set the Java Environment widely in your environment path.

To set java environment, edit /etc/profile.d/ with your favorite editor.

nano /etc/profile.d/

Place the variables based on the JDK location and version.

export PATH=$PATH:/usr/jdk-11.0.3/binexport JAVA_HOME=/usr/jdk-11.0.3export J2SDKDIR=/usr/jdk-11.0.3

Refresh and load your environment in your current session.

source /etc/profile.d/

To set the environment variables permanent, you need to place the variables in ~./bash_profile file.

That’s all, if you have any question about how to install Java DK in your system, do not hesitate to leave a comment below. Thanks.

Originally posted 2019-04-26 00:43:31.

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply