How to install Tomcat7 and Oracle Java on Ubuntu Debian

We assume that you have Ubuntu 12.04 installed (64bit recommended).

First we update default packages –

apt-get update

apt-get upgrade

Once this is complete, we install Oracle Java 7. As this has been excluded from Ubuntu’s repositories, we need to add a new repository using the add-apt-repository command. To use this command, we first install –

apt-get install python-software-properties

To install Oracle Java 7 –

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java7-installer


Debian user: check syntax in 

/etc/apt/sources.list.d/webupd8team-java- .....

and choose the most recent stable version that you can find at the address

, in my case is saucy main

To make sure you have correctly installed it, run –

java -version

You should get the following (or similar) if everything has been installed –

Once Java is installed, let us install Tomcat 7. As Ubuntu 12.04 includes Tomcat 7 by default, no additional repository is required. Just run –

apt-get install tomcat7 tomcat7-admin tomcat7-common tomcat7-docs tomcat7-examples tomcat7-user

tomcat7-docs tomcat7-examples tomcat7-user tomcat7-admin are suggested packages but not necessary for installation / running of Tomcat 7.

After installation, Tomcat 7 will try to start but will fail due to following error –

 * no JDK found – please set JAVA_HOME
invoke-rc.d: initscript tomcat7, action “start” failed.

This error tells us that JAVA_HOME is not set. To resolve this open the file

vi /etc/default/tomcat7

Add the following line and save the file. –

# The home directory of the Java development kit (JDK). You need at least

#JDK version 1.5. If JAVA_HOME is not set, some common directories for

# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.



Now you can try starting Tomcat using the following command –

service tomcat7 start