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.

Extract the zip file inside the /opt/ directory using following command.

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

Now Install Java using 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 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

How to installing java on linux

Now your Your java 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 active java version using 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)

Now 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 comment box.

Read – Install JDK on Linux

Leave a Comment

%d bloggers like this: