How-to Install Oracle JDK 7 On Ubuntu 15.04
Posted on November 23, 2015 • 2 min read • 388 wordsIn this tutorial we'll learn how to install Java Development Kit version 7 on Ubuntu 15.04
Previously we already learn How-to install Oracle JDK 8 on Ubuntu 15.04. Sometimes your application might need older Java version like Java 7.
In this tutorial we’ll learn how to install Java Development Kit version 7 on Ubuntu 15.04
We will install Oracle JDK 7 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
...
OK
```bash
You 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.
```bash
sudo apt-get update
Now, we can install Oracle JDK 7.
sudo apt-get -y install oracle-java7-installer
```bash
Package configuration. Choose **OK**.
[<img loading="lazy" class="aligncenter wp-image-222 size-large" src="https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-2-1024x671.png" alt="how-to-install-oracle-jdk-7-on-ubuntu-15.04-2" width="650" height="426" srcset="https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-2-1024x671.png 1024w, https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-2-300x197.png 300w, https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-2.png 1392w" sizes="(max-width: 650px) 100vw, 650px" />][3]
Accepting **Oracle Binary Code Lisence Terms**. Choose `Yes`
[<img loading="lazy" class="aligncenter wp-image-223 size-large" src="https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-3-1024x671.png" alt="how-to-install-oracle-jdk-7-on-ubuntu-15.04-3" width="650" height="426" srcset="https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-3-1024x671.png 1024w, https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-3-300x197.png 300w, https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-3.png 1392w" sizes="(max-width: 650px) 100vw, 650px" />][4]
After installing Java 7, you can check the current java version by running command below :
```bash
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
We confirmed that we already have JDK 7 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-7-oracle/jre/bin/java
Nothing to configure.
```bash
from the output above we can see that the JAVA_HOME that we need is `/usr/lib/jvm/java-7-oracle/jre/`
On `/etc/environment`, add JAVA_HOME on the last line :
```bash
JAVA_HOME="/usr/lib/jvm/java-7-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 Oracle JDK 7 !");
}
}
```bash
From terminal, run :
```bash
javac HelloWorld.java
If no error, javac should produce HelloWorld.class. To run this file you can use java
$ java HelloWorld
Hello World From Oracle JDK 7 !
We learned how to install Oracle JDK 7 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.