July 18, 2015 in Tutorial2 minutes

Java comes with two different version, JDK or Java Development Kit where you can develop Java app using these compilation of tools. Another version is JRE or Java Runtime Environment, if you only need to run Java application, you can use this. In this tutorial we’ll learn how to install Java Development Kit version 8 on Ubuntu 15.04.
We will install JDK 8 from Webupd8 PPA.
First let’s add webupd8 team PPA repository.
sudo add-apt-repository ppa:webupd8team/java
...
Press [ENTER] to continue or ctrl-c to cancel adding it
...
OKYou need to press enter to continue adding the webupd8team PPA repository. I truncate the output above to show you only the most important part.
Next, we’ll update local metadata to include webupd8 repository.
sudo apt-get updateNow, we can install Oracle JDK 8.
sudo apt-get -y install oracle-java8-installerPackage configuration. Choose OK
Accepting Oracle Binary Code License Terms. Choose Yes
After installing Java 8, you can check the current java version by running command below :
$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)We confirmed that we already have JDK 8 installed.
Let’s check first where java installed
$ sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-oracle/jre/bin/java
Nothing to configure.from the output above we can see that the JAVA_HOME that we need is /usr/lib/jvm/java-8-oracle/jre/
On /etc/environment, add JAVA_HOME on the last line :
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/"Create a new file with name HelloWorld.java with contents below :
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}From terminal, run :
javac HelloWorld.javaIf no error, javac should produce HelloWorld.class. To run this file you can use java
java HelloWorldWe learned how to install JDK 8 on Ubuntu 15.04, setting up JAVA_HOME environment variable that usually needed by Java based application. We also learned how to compile simple Java app and run it.