How to configure Java in Linux server

The Java platform is a suite of programs that facilitate developing and running programs written in the Java programming language. A Java platform will include an execution engine (called a virtual machine), a compiler and a set of libraries; there may also be additional servers and alternative libraries that depend on the requirements. Java is not specific to any processor or operating system as Java platforms have been implemented for a wide variety of hardware and operating systems with a view to enable Java programs to run identically on all of them.

This article explains the detailed steps to configure Oracle Jave in a linux server.

Step1: Download latest version of Java from Oracle official website and extract the package.

For 64 Bit:-

# cd /opt/

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

# tar xzf jdk-7u79-linux-x64.tar.gz

For 32 Bit:-

# cd /opt/

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

# tar xzf jdk-7u79-linux-i586.tar.gz

Step2: Install Java with Alternatives

After extracting Java archive file, we just need to set up to use newer version of Java using alternatives.

# cd /opt/jdk1.7.0_79/

# alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 2

# alternatives --config java

There are 3 programs which provide 'java'.

Selection Command
* 1 /opt/jdk1.7.0_60/bin/java
+ 2 /opt/jdk1.7.0_72/bin/java
3 /opt/jdk1.7.0_79/bin/java

Enter to keep the current selection[+], or type selection number: 3 [Press Enter]

Step3: Set up javac and jar commands path using alternatives command.

# alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 2

# alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 2

# alternatives --set jar /opt/jdk1.7.0_79/bin/jar

# alternatives --set javac /opt/jdk1.7.0_79/bin/javac

Step4: Check Installed Java Version

# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Step5: Configuring Environment Variables

Setup JAVA_HOME variable

# export JAVA_HOME=/opt/jdk1.7.0_79

Setup JRE_HOME Variable

# export JRE_HOME=/opt/jdk1.7.0_79/jre

Setup PATH Variable

# export PATH=$PATH:/opt/jdk1.7.0_79/bin:/opt/jdk1.7.0_79/jre/bin

Leave a Reply