How to install Tomcat7, Oracle Java and Apache virtualhosts on Ubuntu 12.04 LTS

Its been a long time since I posted a how to, but I had promised this one to a WHT member (  ) and I am setting this up for a client right now, so here goes –

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


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

We use mod_jk to pass JSP requests to Tomcat and handle everything else using Apache. To install mod_jk

apt-get install libapache2-mod-jk

Now open the following file –

vi /etc/apache2/

And this text –






4 thoughts on “How to install Tomcat7, Oracle Java and Apache virtualhosts on Ubuntu 12.04 LTS

Leave a Reply

Your email address will not be published. Required fields are marked *