Installing Java and Apache Tomcat on CentOS 6.5 on Amazon EC2

bug tomcat java

How to install Java and Apache Tomcat on Amazon EC2 instance

In this post, we go through quick steps to install Oracle Java or Open JDK and Apache Tomcat on Amazon EC2 Instance. You should be done with the installation within 60 seconds of starting.


  • amazon ec2 instance (assumed available)

First let’s see installation of Oracle Java. First download the latest Oracle JDK to your home directory. Oracle requires to ‘accept’ the licensing agreement before allowing you to start the download. To get around this we add a cookie to the request.

Then unzip the tar file

Now make the following directory for the Java installation. We create a latest directory and them link your current installation to the latest. This way you upgrades can be managed easily. This is only a personal preference.

Now we setup a few environment variables for your Java installation. You might want to add it to your bash profile as well, for them to survive restarts.

Now we check if java is installed properly by running the following command which should tell you the java version.

That’s Oracle JDK installation done. Installing Open JDK is much simpler.

Just as a note you might want to check if Open JDK 6.0 is already installed on the instance. If Open JDK 6.0 is installed you can either remove it or just switch to using the latest installed java as follows

That’s java installation done. Please remember you want to use either Open JDK or Oracle JDK and not both.

Installing Apache Tomcat 7 is even more straightforward than Open JDK.

You can check the installation as follows

Here’s how you can start and stop Apache Tomcat after installation.

That’s it you are done! Enjoy Apache Tomcat and your Java.


After receiving some questions about installing Apache Tomcat without RPM, here’s a new post on Installing Apache Tomcat on Amazon EC2 without using RPM