Some of you may found yourself in the situation where it is necessary to install the “original” Oracle Java 7 on Ubuntu, for example because you want to run Glassfish or Tomcat on your server. Downloading the official archive from Oracle is not the problem, but the complexity starts with the installation- and especially the configuration process of the extracted Java 7 directories. As an user you can make many mistakes by missconfiguration and can lose yourself in the jungle. But there is hope. There is an easier way of installing the original Oracle Java 7 on Ubuntu.
The reason for writing this blog post is, that I will document how to install Glassfish 4.0 on Ubuntu 12.04 LTS server and therefore I decided to use Oracle’s Java 7, because a Java Runtime Environment is a requirement for running a servlet container. The installation of Glassfish will be covered in the next blog post.
Adding a new repository
The main path to the goal is to add an user/community maintained Ubuntu repository from http://www.webupd8.org/, but therefore we need to install some tools first.
sudo apt-get install python-software-properties sudo apt-get install software-properties-common
I would also advise you to restart the server/maschine, to prevent some error caused by the “add-apt-repository” command.
Now we can add the necessary repository into Ubuntu’s sources list:
You will be asked if you are sure adding this repository. Just confirm by pressing “ENTER”.
Installing Oracle Java 7
After that we are nearly ready do install the needed Oracle Java 7. We only need to update the sources and after that we can install the wished version. You can also change the version number in the command and install Oracle Java 6 or Oracle Java 8 on Ubuntu.
sudo apt-get update sudo apt-get install oracle-java7-installer
Confirm the licence agreement.
Checking if it worked
The last thing to do is to check if Java was successfully installed. We will do this by the use of the following command:
The result should be something like this:
java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)