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 !!!
Thank you, it was a very helpful article!
Thanks for the comment and keep in touch with this blog, more is coming.. 🙂
Or you could simply use:
sudo apt-get install tomcat6
Thanks for your comment.
Thanks Jan. Yeah! you can simply use that command.
hi, that’s a discriminating aeronaut. There is whatever mistakes but the primary is here.
got this output: can you help
sh: Can’t open /usr/local/tomcat/bin/startup.sh
@vidur,
Its not to edit. that starts the service
dont worry about that
thinks lot of it was very clear .
Rocking post, simple and effective
Thanks for comments. Keep in touch with it for more upcoming posts…
Thanks a lot for this nice piece of work. It helped me much to set up Incinga and Funambol Server with java-6-openjdk and apache Tomcat I only changed the wget command to get the newest one: wget http://apache.tradebit.com/pub/tomcat/tomcat-7/v7.0.30/bin/apache-tomcat-7.0.30.tar.gz …and the following lines for unpacking and moving the folder
Greetings from Dresden, Germany
Thanks for your comment. It’s better that you used the newest download link.
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.
Thanks for figuring out the typo. Fixed 🙂