Install Oracle JDK on Ubuntu

This article describes how to install Oracle JDK on Ubuntu. There are two ways to it.

Way I. Install Oracle JDK via PPA

Run in terminal:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Way II. Manual installation

Download jdk-8-linux-i586.tar.gz or jdk-8-linux-x64.tar.gz from Oracle official website.
Run the following commands in terminal:

tar -xvf jdk-8-linux-x64.tar.gz
sudo mkdir -p /usr/lib/jvm
sudo mv ./jdk1.8.0 /usr/lib/jvm/

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

sudo chmod a+x /usr/bin/java 
sudo chmod a+x /usr/bin/javac 
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.8.0

sudo update-alternatives --config java

Install Mozilla Firefox Java plugin (for single user)

32 bit:

ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

64 bit:

ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Install Mozilla Firefox Java plugin (for all users)

32 bit:

sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins/

64 bit:

sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins/

Install Google Chrome Java plugin

32 bit:

sudo mkdir -p /opt/google/chrome/plugins
cd /opt/google/chrome/plugins
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

64 bit:

sudo mkdir -p /opt/google/chrome/plugins
cd /opt/google/chrome/plugins
sudo ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Conclusion

To check active Java version run in terminal:

java -version
javac -version