java tutorial - How to install Java on Linux - java programming - learn java - java basics - java for beginners
Install JAVA on Linux Systems
- The Java can be installed and running on same computer as well as it’s possible to have different version of JDK and JRE at the same time on a machine, actually there are abundant of applications that requires Java-jre (Java Runtime Environment) and those who are developer required Java-sdk (Software Development Kit).
- Many of Linux distribution comes under additional version of Java known as OpenJDK (not the one developed by Sun Microsystems and then acquired by Oracle Corporation).
- The OpenJDK is open source implementation of Java application.
Steps to Install Java in Linux
Step 1
- Before installing Java, make sure to initial verify the version of installed Java.
# java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-2)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
- It’s clear from the output above that the installed version of Java is OpenJDK 1.7.0_75.
Step 2
- Make a directory where you want to install Java. For global access (for all users) install it preferably in the directory /opt/java.
/opt/java.
# mkdir /opt/java && cd /opt/java
Step 3
- Now download Java (JDK) 8u45 source tarball files for your system architecture by going to official Java download page.
- For reference, we have provided the source tarball file-names, please select and download these under mentioned files only.
jdk-8u45-linux-i586.tar.gz [For 32-bit Systems]
jdk-8u45-linux-x64.tar.gz [For 64-bit Systems]
- Otherwise, you may use wget command to download files directly into the
/opt/java
directory as shown below.
--------------- For 32-bit Systems ---------------
# cd /opt/java
# 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/8u45-b14/jdk-8u45-linux-i586.tar.gz"
--------------- For 64-bit Systems --------------
# cd /opt/java
# 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/8u45-b14/jdk-8u45-linux-x64.tar.gz"
Step 4
- Once file has been downloaded, you may extract the tarball using tar command as shown below.
# tar -zxvf jdk-8u45-linux-i586.tar.gz [For 32-bit Systems]
# tar -zxvf jdk-8u45-linux-x64.tar.gz [For 64-bit Systems]
Step 5
- From that point onwards, move to the already extracted directory and to utilize command update-alternatives then to inform system where java as well as its executables are installed.
# cd jdk1.8.0_45/
# update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.0_45/bin/java 100
# update-alternatives --config java

Learn Java - Java tutorial - Update java alternatives - Java examples - Java programs
Step 6
- System to update javac alternatives as,
# update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_45/bin/javac 100
# update-alternatives --config javac

Learn Java - Java tutorial - Update javac alternatives 1 - Java examples - Java programs
Step 7
- Likewise, update jar alternatives as:
# update-alternatives --install /usr/bin/jar jar /opt/java/jdk1.8.0_45/bin/jar 100
# update-alternatives --config jar

Learn Java - Java tutorial - Update Jar Alternatives - Java examples - Java programs
Step 8
- Now you have to setting up Java Environment Variables.
# export JAVA_HOME=/opt/java/jdk1.8.0_45/
# export JRE_HOME=/opt/java/jdk1.8.0._45/jre
# export PATH=$PATH:/opt/java/jdk1.8.0_45/bin:/opt/java/jdk1.8.0_45/jre/bin

Learn Java - Java tutorial - Set Java Path - Java examples - Java programs
Step 9
- Presently you can check the Java version another time, to confirm.
# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
- Optional: If you are not using OpenJDK (open source implementation of java), you may eliminate it as:
# apt-get remove openjdk-*
Enable Java Support in Firefox
Step 10
- To enable Java 8 JDK 8u45 Support in Firefox, you require running the following commands to allow Java module for Firefox.
On Debian, Ubuntu and Mint
--------------- For 32-bit Systems ---------------
# update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /opt/java/jdk1.8.0_45/jre/lib/i386/libnpjp2.so 20000
--------------- For 64-bit Systems ---------------
# update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /opt/java/jdk1.8.0_45/jre/lib/amd64/libnpjp2.so 20000
On RHEL, CentOS and Fedora
--------------- For 32-bit Systems ---------------
# alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /opt/java/jdk1.8.0_45/jre/lib/i386/libnpjp2.so 20000
--------------- For 64-bit Systems ---------------
# alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /opt/java/jdk1.8.0_45/jre/lib/amd64/libnpjp2.so 20000
Step 11
- Finally verify the Java support by restart the Firefox and enter about:plugins on the address bar. You will get similar to below screen.

Learn Java - Java tutorial - Java support in firefox - Java examples - Java programs