How-to Install Oracle JDK 7 On Ubuntu 15.04
Categories:
Overview
Previously we already learn [How-to install Oracle JDK 8 on Ubuntu 15.04][1]. 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
Install Java Development Kit (JDK) 7
We will install Oracle JDK 7 from [Webupd8 PPA][2].
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
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.
$ sudo apt-get update
Now, we can install Oracle JDK 7.
$ sudo apt-get -y install oracle-java7-installer
Package configuration. Choose OK.
[][3]
Accepting Oracle Binary Code Lisence Terms. Choose Yes
[][4]
After installing Java 7, you can check the current java version by running command below :
$ 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.
Setting Up JAVA_HOME
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.
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 :
JAVA_HOME="/usr/lib/jvm/java-7-oracle/jre/"
Trying Java 7
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 !");
}
}
```
From terminal, run :
```
$ 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 !
```
## Summary
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.
[1]: https://www.howtodojo.com/2015/07/how-to-install-jdk-8-on-ubuntu-15-04/
[2]: https://launchpad.net/~nilarimogard/+archive/ubuntu/webupd8
[3]: https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-2.png
[4]: https://www.howtodojo.com/wp-content/uploads/2015/11/how-to-install-oracle-jdk-7-on-ubuntu-15.04-3.png