Architecture
First we check which architecture we are running on.
Open a terminal and type the command arch.
The output could be i686 or i386 for a 32 bits system or x86_64 for a 64 bits system.
Environment
Your environment could already have an installation or not.
Open a terminal and run the following command :
user@machine:~$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) Server VM (build 25.25-b02, mixed mode)
user@machine:~$
In the previous output we can see that the command has been successfully executed. It gives us the default version.
Then run the following command :
user@machine:~$ update-java-alternatives -l
java-1.6.0-openjdk-i386 1061 /usr/lib/jvm/java-1.6.0-openjdk-i386
java-1.7.0-openjdk-i386 1071 /usr/lib/jvm/java-1.7.0-openjdk-i386
java-1.8.0-openjdk-i386 1069 /usr/lib/jvm/java-1.8.0-openjdk-i386
java-8-openjdk-i386 1069 /usr/lib/jvm/java-8-openjdk-i386
user@machine:~$
The current installation shows that several JVM are installed.
Installation
Run the following command in order to install or update the Open JDK 8. The idea is applicable to others JVM.
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
if you have more than one Java versions installed on your system. Run the following command and select the desired one.
user@machine:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java 1071 auto mode
1 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java 1071 manual mode
* 3 /usr/lib/jvm/java-8-openjdk-i386/jre/bin/java 1069 manual mode
Press enter to keep the current choice[*], or type selection number:
Set the default Java Compiler by running:
sudo update-alternatives --config javac