Install JAVA on Linux

Install JAVA on Linux

How to Install JAVA 8 on Linux using the compiled source code?

In this article, I’m going to show you how to install java 8 using the compiled source code on Redhat Linux, CentOS, and Fedora also the same steps.

Step 1. Extract the zip file

Extract downloaded source code inside the /opt/ directory using the following command.

#tar -zxf jdk-8u201-linux-x64.tar.gz -d /opt/

Step 2. Install Java using the alternative command.

#alternatives --install /usr/bin/java java /opt/jdk1.8.0_201/bin/java 2
#alternatives --config java 

As you can see there is two java installed, New java is listed on number 2, so press 2.

There are 2 programs which provide 'java'.

Selection Command
* 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
+ 2 /opt/jdk1.8.0_201/bin/java
Enter to keep the current selection[+], or type selection number: 2

Now your java is installed successfully. After doing this we need to setup the javac and jar command path using the following commands.

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

Check the active java version using the following command.

#java -version

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Step 3. Setup Environment variables

Now we need to set Java Environment Variables in .bash_profile.

# vi .bas_profile

export JAVA_HOME=/opt/jdk1.8.0_201
export JRE_HOME=/opt/jdk1.8.0_201/jre
export PATH=$PATH:/opt/jdk1.8.0_201/bin:/opt/jdk1.8.0_201/jre/bin

Thanks for reading, If you got this article informative please write in the comment box.

Read - Install JDK on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top