Install JDK 8 on Ubuntu

Installing step by step Oracle JDK 8 on Ubuntu GNU/Linux:

Step 1: Download the Oracle JDK 8 tar file from here.

Step 2: Open the terminal and extract the tar file.

tar -xvzf jdk-8-linux-x64.tar.gz

Step 3: Create jvm folder in /usr/lib, if jvm folder not exist.

sudo mkdir /usr/lib/jvm

Step 4: Move extracted JDK 8 folder to this location.

sudo mv jdk1.8.0 /usr/lib/jvm/jdk1.8.0

Step 5: Install new Java source in system.

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8.0/bin/javaws 1

Step 6: Choose default Java.

sudo update-alternatives --config javac
sudo update-alternatives --config java
sudo update-alternatives --config javaws

Step 7: Test the Java version.

java -version

# java version "1.8.0"
# Java(TM) SE Runtime Environment (build 1.8.0-b132)
# Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

Step 8: Verify the symlinks all point to the new Java location.

ls -la /etc/alternatives/java*

Step 9: Enable Java plugin for Mozilla Firefox (even for Chrome)

# for 64-Bit JDK
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins
# for 32-Bit JDK
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins

Step 10: Some tools require JAVA_HOME variable. You can set JAVA_HOME variable on Ubuntu with following options (1. option recommended!)

  1. Option with /etc/environment:
    sudo gedit /etc/environment
    # add the following line, save and exit
    JAVA_HOME=/usr/lib/jvm/jdk1.8.0
    
    # Load the variables
    source /etc/environment
    
  2. Option with .bashrc: in your home directory
    sudo gedit .bashrc
    # add the following lines, save and exit
    export JAVA_HOME=/usr/lib/jvm/jdk1.8.0
    export PATH=$JAVA_HOME/bin:$PATH

 

Original post is from my old devsniper.com blog!