Share this:

Many times i faced issues with installing java using rpm or other source. After that i found a better way to install java from Sun site. Using below steps i have installed java successfully many times without facing any issues. We can also install multiple version of java easily if required. Oracle has also released Java 8. To install it read article Install Java 8 in CentOS, Redhat and Fedora.

linux-with-java

Use following step by step instructions to install or update java. I recommend to read carefully instruction for downloading java from Linux command line.

Step 1: Download Archive File

Download latest version of java from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.

# cd /opt/
# wget http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-i586.tar.gz?AuthParam=1390449913_60183bed2462c33ac44293ffc30614d9

Note: Above wget command will not work because of AuthParam code expires after some time, So if you need to download it through Linux terminal, watch below screencast ( http://screencast.com/t/wf9bQ0XjDPxT ), You are required a graphical browser.

After completing download, Extract archive using following command.

# tar xzf jdk-7u51-linux-i586.tar.gz
Step 2: Install JAVA using Alternatives

After extracting java archive file, we just need to setup to use newer version of java using alternatives. Use the following commands to do it.

# cd /opt/jdk1.7.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_51/bin/java 2
# alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /opt/jdk1.7.0_25/bin/java
*  2           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
 + 3           /opt/jdk1.7.0_45/bin/java
   4           /opt/jdk1.7.0_51/bin/java

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

Now you have successfully configured java in your system. Go to next step to check current installed version.

Step 3: Check Version of JAVA .

Use following command to check which version of java is currently being used by system.

# java -version

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode)

Step 4: Setup Environment Variables

Most of java based application’s uses environment variables to work. Use following commands to setup it.

  • Setup JAVA_HOME Variable
  • # export JAVA_HOME=/opt/jdk1.7.0_51
    
  • Setup JRE_HOME Variable
  • # export JRE_HOME=/opt/jdk1.7.0_51/jre
    
  • Setup PATH Variable
  • # export PATH=$PATH:/opt/jdk1.7.0_51/bin:/opt/jdk1.7.0_51/jre/bin
    

I hope above steps will help you for installation java on your Linux system. You can follow above steps to install multiple version of java as same time but you can use only one version at a time.

Thanks