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
In repository, there are several version of OpenJDK as followings:
java-1.8.0-openjdk.x86_64 # To execute java applications.java-1.8.0-openjdk-devel.x86_64 # 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
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" https://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.3_linux-x64_bin.tar.gz
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-18.104.22.168.b12-0.el7_5.x86_64/jre/bin/java) 2 /usr/jdk-11.0.3/bin/javaEnter to keep the current selection[+], or type selection number: 2
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.
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.
To set the environment variables permanent, you need to place the variables in
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.