Get the latest tar.gz version for Linux from:
Open the terminal and move to the directory containing the tar.gz file
The filename will look something like jdk1.8.0_XX where XX will change because of updates. From 1.8 we know this is Java 8.
Once downloaded, decompress the tar.gz using the following command
tar -xzf jdk1.8.0_*
You will see the folder in the directory where you ran this command if it is successful.
Move it to a suitable location.. I used /usr/java as the folder for this. You probably wont have this folder on a fresh installation so
sudo mkdir /usr/java
Next if you are currently in the folder containing the decompressed jdk, we will move both the tar.gz and the folder you decompressed into the /usr/java directory.
mv jdk* /usr/java
Next in order for applications to know where the jdk is you need to have the value available to JAVA_HOME. I will tell you the steps to permanently set this variable.
We want the system to know where our java javac and javaws executables are
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_XX/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_XX/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_XX/bin/javaws" 1
Again, don’t forget to replace the XXs with the update number.
We want to make sure the jdk is accessible to all user and application for execution so for each executable you find in the bin folder that you plan to use the following command as an example of what you need to execute. Again don’t forget to replace the XXs with the update number.
sudo chmod a+x /usr/java/jdk1.8.0_XX/bin/java
sudo chmod a+x /usr/java/jdk1.8.0_XX/bin/javac
sudo chmod a+x /usr/java/jdk1.8.0_XX/bin/javaws