Java Installation in Linux

1
59

JAVA

Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to data centers, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere.

There are many places where Java is used in real world, starting from commercial e-commerce website to android apps, from scientific application to financial applications like electronic trading systems, from games like Minecraft to desktop applications like Eclipse, Net-beans and IntelliJ, from open source library to J2ME apps etc.

Many server side applications are written in Java to process tens of millions of requests per day, high frequency trading applications are also written in Java e.g. LMAX trading applications, which is built over their path breaking inter-thread communication library.
In this artical we will known about how to install java in linux

First Change the directory to where the Java to be installed

[root@localhost ~]# cd /opt/

Then Download latest version of java from their official site.

From this website we can download java by choosing the options like java version,type and architecture. Here i choose the version 8u91(latest version).

[root@localhost opt]#wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz 

After the completion of Download Extract the archive jdk-8u91-linux-x64.tar.gz

[root@localhost opt]#tar xzf  jdk-8u91-linux-x64.tar.gz

When the extraction is completed change to the directory jdk1.8.0_91

[root@localhost opt]# cd jdk1.8.0_91/

Now change the already installed java defaults

[root@localhost jdk1.8.0_91]# alternatives --install /usr/bin/java java /opt/jdk1.8.0_91/bin/java 2
[root@localhost jdk1.8.0_91]# alternatives --config java
There are 4 programs which provide 'java'.
  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64/jre/bin/java
*  2           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jre/bin/java
 + 3           /opt/jdk1.7.0_79/bin/java
   4           /opt/jdk1.8.0_91/bin/java
 
Enter to keep the current selection[+], or type selection number: 4
[root@localhost jdk1.8.0_91]#

Now check the java version by using the command java -version.

[root@localhost ~]# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Now set the paths for JAVA_HOME, JRE_HOME and also set the path for java as follows

[root@localhost jdk1.8.0_91]#export JAVA_HOME=/opt/jdk1.8.0_91
[root@localhost jdk1.8.0_91]#alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_91/bin/jar 2
[root@localhost jdk1.8.0_91]#alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_91/bin/javac 2
[root@localhost jdk1.8.0_91]#alternatives --set jar /opt/jdk1.8.0_91/bin/jar
[root@localhost jdk1.8.0_91]#alternatives --set javac /opt/jdk1.8.0_91/bin/javac
[root@localhost jdk1.8.0_91]#export JRE_HOME=/opt/jdk1.8.0_91/jre
[root@localhost jdk1.8.0_91]#export PATH=$PATH:/opt/jdk1.8.0_91/bin:/opt/jdk1.8.0_91/jre/bin

Check the JAVA_HOME, JRE_HOME by using the echo command as follows

[root@localhost ~]# echo $JAVA_HOME
   /opt/jdk1.8.0_91
[root@localhost ~]# echo $JRE_HOME
  /opt/jdk1.8.0_91/jre
[root@localhost ~]#

Now we can run the java programs and also install the java based packages like Tomcat, Glass Fish and Jenkins.

Comments

comments

1 COMMENT

  1. Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. I’ll give you a link on your web blog. I recently came to know about http://machinesuae.com/, their Computers And Technology are very effective.
    Computers And Technology Thanks for sharing.