How to install Java 8 OpenJDK

In order to install the Java 8 SDK, we can follow two procedures

First Option

1. Add the repository to get openjdk

sudo add-apt-repository ppa:openjdk-r/ppa

2. Update the repositories

sudo apt-get update

3. Install the openjdk-8-jdk

sudo apt-get install openjdk-8-jdk

4. Configure java 

sudo update-alternatives --config java

5. Configure javac

sudo update-alternatives --config javac

​Second Option

1. Get the jdk tar gz file

wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz

2. Become root in your machine

sudo su

3. make a directory /opt/jdk

mkdir /opt/jdk

4. untar the downloaded file

tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

5. verify that the files are within the already created directory

ls /opt/jdk

6. Update the alternatives to link java command to the jdk directory

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100

7. Update the alternatives to link javac command to the jdk directory

update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

8. Verify to which directory does the java command is pointing to 

update-alternatives --display java

9. Verify to which directory does the javac command is pointing to

update-alternatives --display javac

Reference