I use the operating system is Ubuntu 12.04, the default can only install jdk1.6 version, if you need to install 1.8 version, then need to follow the steps below.

Step #1: Install Capability to Manage Repositories

sudo apt-get install python-software-properties

Step #2: Add the WebUpd8 Team Personal Package Archive (PPA)

sudo apt-add-repository ppa:webupd8team/java

Step #3: The Installation

sudo apt-get update
sudo apt-get install oracle-java8-installer

Step #4: Verify Installation

java -version

#Step 5.Configure the default JDK

vi /etc/profile

Add the following

JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/lib
export JAVA_HOME PATH CLASSPATH

Other:
View the default jdk.

echo $JAVA_HOME

View the JDK version:

java -version