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

Ref: http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html

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  

http://ppa.launchpad.net/webupd8team/java/ubuntu

, in my case is  

http://ppa.launchpad.net/webupd8team/java/ubuntu 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.

#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk

JAVA_HOME=/usr/lib/jvm/java-7-oracle

Now you can try starting Tomcat using the following command –

service tomcat7 start

from http://leapswitch.com/blog/technical-solutions/how-to-install-tomcat7-oracle-java-apache-virtualhosts-ubuntu-12-04-lts/