Install Apache Tomcat server with Open JDK on Ubuntu

I need to run JavaServer Pages(JSP) in one of my client projects. So, I installed Apache Tomcat server on my Ubuntu. Basically, Apache Tomcat is an open source software implementation for Java Servlet and JSP. I will show you the manual way to install on OpenJDK implementation of Java. You can also run tomcat on Sun’s Java implementation. It’s not so tough. Just follow my steps.

Make sure that your PC has installed Java. If not, then don’t worry. I will show all steps related to install it properly. Open terminal and type following line

sudo apt-get install openjdk-6-jre

Now you can check, weather Java is installed or not. So, type

java -version

it will show similar message to the below

java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)

Tomcat requires setting the JAVA_HOME variable. So, I edit the ~/.bashrc file by test editor

sudo nano ~/.bashrc

And add the following line . .

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk

Environment is ready for Tomcat server. Now only installing part is left. . . .

You will have to download tomcat from Apache Website. You can download it from the website: http://tomcat.apache.org/download-60.cgi

Or you can download it in commandline

wget http://apache.tradebit.com/pub/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz

Then extract it on Desktop. Type ..

tar -xvzf apache-tomcat-6.0.32.tar.gz

Move it to the location /usr/local/tomcat

sudo mv apache-tomcat-6.0.32 /usr/local/tomcat

Now you will have to give permission to tomcat directory

sudo chmod -R 755 /usr/local/tomcat

If you want to start tomcat automatically when your PC is started, then you will have to add a script to /etc/init.d.

sudo nano /etc/init.d/tomcat

Just copy and paste following lines…

# Tomcat server auto-start script

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk

 

 

case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

Now you will have to make this script executable. So, again you will have to give the permission to the file /etc/init.d/tomcat

sudo chmod 755 /etc/init.d/tomcat

Now, you will have to link this script to the startup folders by a symbolic link. So, just type following commands

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat<br />
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat<br />

Type following line to start the tomcat server

sh /usr/local/tomcat/bin/startup.sh

It will show you the following messages . .

Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar

Done. Your tomcat server is working .. Now Point your browser to : http://localhost:8080

To stop tomcat server, just type

sh /usr/local/tomcat/bin/shutdown.sh

Keep it in your mind, you can also use sun-java-jdk instead of openjdk. Have a happy journey in the open source world !!!

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

16 thoughts on “Install Apache Tomcat server with Open JDK on Ubuntu

  1. Thank you so much, your article was a life saver, esp for an amateur like me.
    small correction though, about tar xvzf , must be a typo has to be tar -xvzf.

    Thanks.

    Cheers,
    Vj.

Leave a Reply

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

 

Read previous post:
Install Sun Java JDK and JRE on Ubuntu

Just type few lines and install it. First, enable the repository by editing /etc/apt/sources.list. So, open the source list by...

Close