Apache has officially launched version 7.0 of the servlet container for Java applications, Tomcat. Major changes in this version, you can highlight support for Servlet 3.0 and JavaServer Pages 2.2.
Install JDK
See this post: Install JDK 6 update 23 in Ubuntu 10.10 Installation
The first thing to do is download the package "apache-tomcat-7.0.6.tar.gz" from the NEXT link
http://tomcat.apache.org/download-70.cgi [tar.gz]Now unpack it with the following command:
tar xvzf apache-tomcat-7.0.8.tar.gz
Then we let in a more appropriate directory, in our case in / usr/share/tomcat7, but can be in any directory. We do this with the command:
sudo mv apache-tomcat-7.0.8/ /usr/share/tomcat7
Now we define the environment variables JAVA_HOME and JRE_HOME. This file is in the "environment" in / etc. Command to edit the file:
sudo gedit /etc/environment
Here we record the routes where we have installed Java in my case this is as follows:
JAVA_HOME="/usr/local/jdk1.6.0_23"JRE_HOME="/usr/local/jdk1.6.0_23/jre"PATH="...(other path):$JAVA_HOME:$JRE_HOME"
IMPORTANT: Verify the routes where they have installed Java.
I have had some problems in defining these environment variables, as sometimes tomcat does not recognize, but a surefire way of recognizing that tomcat is to define the file paths inside "catalina.sh"located in tomcat7/bin. To modify this file use the command:
sudo gedit /usr/share/tomcat7/bin/catalina.sh
Now just insert the JAVA_HOME and JRE_HOME after the first line, so the file is as follows:
#!/bin/sh
JAVA_HOME="/usr/local/jdk1.6.0_23"
JRE_HOME="/usr/local/jdk1.6.0_23/jre"
# Licensed to the Apache Software Foundation (ASF)...
#...
#...
....
Now let's configure Tomcat users, this is done in the file "tomcat-users.xml"directory tomcat7/conf. Command to edit the file:
sudo gedit /usr/share/tomcat7/conf/tomcat-users.xml
Unlike previous versions where the administrator should own role "manager" now it should be "manager-gui"to operate on the web administration tomcat7. The file would be as follows:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/><role rolename="manager-script"/><role rolename="manager"/><role rolename="admin-gui"/><role rolename="admin-script"/><role rolename="admin"/> <user username="usuario" password="contrasena" roles="manager-gui,admin-gui,manager,admin,manager-script,admin-script"/>
</tomcat-users>

Now you should be all ready to try tomcat7.
First we must lift the server with the following command:
sudo /usr/share/tomcat7/bin/startup.sh
With this we get the following output on console:
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using JRE_HOME: /usr/local/jdk1.6.0_20/jre
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
Verify that the JRE_HOME is where we define.
Now open your web browser and type the following url:
http://127.0.0.1:8080/
So we get the following page:
If we enter the administration Tomcat Manager we click on the menu or directly at URL:
http://127.0.0.1:8080/manager/html
Here we ask the user data from previous record in mind tomcat-users.xml.
I recommend testing the sample to make sure everything works ok, they are in the section "Miscellaneous" from the side menu or at the URL:
http://127.0.0.1:8080/examples/
Commands
Start server:
sudo /usr/share/tomcat7/bin/startup.sh
Stop server:
sudo /usr/share/tomcat7/bin/shutdown.sh
Automatic Starting
To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.
sudo gedit /etc/init.d/tomcat7
Now paste in the following:
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
case $1 in
start)
sh /usr/share/tomcat7/bin/startup.sh
;;
stop)
sh /usr/share/tomcat7/bin/shutdown.sh
;;
restart)
sh /usr/share/tomcat7/bin/shutdown.sh
sh /usr/share/tomcat7/bin/startup.sh
;;
esac
exit 0
You’ll need to make the script executable by running the chmod command:
sudo chmod 755 /etc/init.d/tomcat7
The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.
sudo ln -s /etc/init.d/tomcat7 /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat7 /etc/rc2.d/S99tomcat
Tomcat should now be fully installed and operational. Enjoy!
sudo /etc/init.d/tomcat7 restart

Excelente post Diego!!
RispondiEliminaMuy útil!
Thanks!
Eliminathe best ! 10x !
RispondiEliminaThanks.
RispondiEliminaIs there an apt-get equivalence?
Why? :)
RispondiEliminacan you explain difference between /etc/environment here and in install jdk 6 blog? Actually i think on this: JAVA_HOME="/usr/local/jdk1.6.0_23". Is it ok without bin directory.
RispondiEliminaSorry, i'm complete noob, so i need explaination.
Thanks anyway
Grazie mille, Diego! Sei stato moltíssimo gentile!
RispondiEliminaFYI -- I just successfully used this and related posts to upgrade my Ubuntu 10.04 java to 1.6.0_24 and to install Tomcat 7.0.12.
RispondiEliminaNow I'm coding/debugging/testing my new java servlet. All this on a Dell Latitude D610 with 1 gig of ram. Hums along nicely.
Thank you for these clear instructions.
Getting Tomcat going is usually a time consuming frustration. I was fearing it to be even worse since this is the first time in years I was going to do it on an Ubuntu box. The Linux people love to shuffle Java directories around.
RispondiEliminaYour post was extremely useful and convenient.
Thank you very kindly for posting it.
Steve
XD Thank you! this is tested!!
RispondiEliminaI needed this badly. The explanation is easy to understand. It worked for me. Thank you.
RispondiEliminathank you for your generous post from quebec canada :) STEF
RispondiEliminawow... very easy! i love you man...you save a lot of time mine
RispondiEliminaI don't know why but startup part didn't work for me after 1 hour of struggle I ended up running this command:
RispondiElimina#update-rc.d tomcat7 defaults
the only different was the name of symbolic links:S20tomcat7 for S99tomcat and K01tomcat7 for K99tomcat.
I tried to install tomcat7 but I had some difficulties. Having read your post and the comments I have found the facts which helped me a lot and I fixed everything.
RispondiEliminaQuesto commento è stato eliminato dall'autore.
RispondiElimina"I have had some problems in defining these environment variables, as sometimes tomcat does not recognize..."
RispondiEliminaThe problem you are facing is that your /etc/sudoers is configured with
Defaults env_reset
One has to run your slightly modified command to use system-wide environment variables:
sudo -E /usr/share/tomcat7/bin/startup.sh
Excellent tutorial, straight to the point. Good work.
RispondiEliminaGood guide!
RispondiEliminaThanks really. I really needed to get this going. Fairly easy to understand.
RispondiEliminaGreat. Now that this path was used /usr/share/, the sysaid installation is not working. And I can not remove tomcat7 anymore, because ubuntu doesnt find the package.
RispondiEliminaHOW DO I REMOVE IT ??
RispondiEliminaDon't run tomcat as root! That's not very secure. Create a special tomcat user, run tomcat as that, and you'll probably need to change the rights for some folders to that tomcat user.
RispondiEliminaGreat explanation Diego!!!
RispondiEliminaOne strange thing that it happened to me and I do not know why. I installed Tomcat 7.0.22 in an Ubuntu Server 11.04. When I access Tomcat from my client laptop, an Ubuntu 10.04, via Chrome the tomcat homepage is in English, but some other tomcat pages like "List of applications" are in Spanish. I installed both system, Ubuntu server and Ubuntu desktop in English. The only Spanish thing installed is the Spanish keyboard in the Ubuntu desktop because sometimes I need to write in Spanish, but the laptop is British. So rare, isn't it?
Any idea?
One more thing, in firefox doesn't happen. Everything is in English, so what's going on in Chorme?
RispondiEliminaThanks for the follow through I was able to use this with JDK1.7.01 and tc7.
RispondiEliminaPossibly dumb question - but why are you writing to rc1.d and rc2.d? Wouldn't you only want tomcat to start in runlevels 3 and 5 - with the network? And is there a reason not to use update-rc.d?
RispondiEliminathx for the post.
RispondiEliminaThanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
RispondiEliminaAsking password n Login Id
RispondiEliminaThanks a lot, it works perfectly ! :)
RispondiEliminaThis blog is really good. Good posting done. Keep it up..
RispondiEliminaViejo, muchas gracias por tu ayuda, mas fácil no puede ser.
RispondiEliminaFelicitaciones
Perfect! No flaws!
RispondiEliminaThank you.
Ciao Diego!
RispondiEliminanon riesco a capire come mai nonostante il mio file /etc/environment sia:
JAVA_HOME = "/usr/local/jdk1.6.0_31/bin/"
JRE_HOME = "/usr/local/jdk1.6.0_31/jre"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$JAVA_HOME:$JRE_HOME"
poi quando faccio partire tomcat con
sudo /usr/share/tomcat7/bin/startup.sh
ottengo:
/usr/share/tomcat7/bin/catalina.sh: 2: JAVA_HOME: not found
/usr/share/tomcat7/bin/catalina.sh: 3: JRE_HOME: not found
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
ho seguito la tua guida per installare java (nel mio caso 6.31)
grazie in anticipo
hi hoping this is useful i suggest you to restart linux for allowing settings in /etc/environment taking effect
Eliminahi
Got that up and running with no trouble. Very nicely explained helped me out. Thank you.
RispondiEliminaThank a lot !! It works and make it easy the installation process!!
RispondiEliminaBest regards!!
Thank you!
RispondiEliminaVery good post, Diego. Thanks a lot ! :)
RispondiEliminaThank you! Tomcat running
RispondiEliminaATT
João Batista Ladchuk
Very nice post. I just stumbled upon your blog and wished to say that I have truly enjoyed surfing around your blog posts. In any case I’ll be subscribing to your rss feed and I hope you write again soon.
RispondiEliminaGreat !
RispondiEliminathankyou.....
Is doesn't work .......
RispondiEliminaThanks for sharing such a nice post
RispondiEliminaregards...
nice post, it works to me :)
RispondiEliminaSirvió de mucho gracias capo!!!
RispondiEliminaWhy not just apt-get install tomcat7? Much easier.
RispondiEliminaJAVA_HOME should not have /bin on the end, else very good
RispondiEliminaawesometown. Had me up and running in 45min. Thank you!
RispondiEliminahi,
RispondiEliminaI followed all the above steps. But when i tried executing startup.sh, i got the following output on the console.....
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME: /usr/local/jdk1.6.0_35/jre
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
touch: cannot touch `/usr/share/tomcat7/logs/catalina.out': No such file or directory
/usr/share/tomcat7/bin/catalina.sh: 390: /usr/share/tomcat7/bin/catalina.sh: cannot create /usr/share/tomcat7/logs/catalina.out: Directory nonexistent
Please help..
thanku
I was able to circumvent the environment variables problem (no more need to add JAVA_HOME and JRE_HOME to catalina.sh) with this start script:
RispondiElimina#!/bin/bash
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
for line in $( cat /etc/environment ) ; do
if [[ "$line" == *"_HOME="* ]]; then
export $line
fi
done
case $1 in
start)
sh /opt/apache-tomcat-7.0.30/bin/startup.sh
;;
stop)
sh /opt/apache-tomcat-7.0.30/bin/shutdown.sh
;;
restart)
sh /opt/apache-tomcat-7.0.30/bin/startup.sh
sh /opt/apache-tomcat-7.0.30/bin/shutdown.sh
;;
esac
exit 0
you're awesome guys
RispondiEliminaI am using ubuntu 12.04 and tomcat 6.I followed all the above steps. But when i tried executing startup.sh, i got the following output on the console.....
RispondiEliminaUsing CATALINA_BASE: /usr/share/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME: /usr/local/java/jdk1.7.0_07/jre
Using CLASSPATH: /usr/share/tomcat6/bin/bootstrap.jar
..Please help me.
I have research your web page and I got very useful and knowledgeable information from your web page. It’s really a very amazing material. You have done an outstanding job. Thank you so much for sharing about Tomcat 7 on Ubuntu.
RispondiEliminaI had a great time reading your article and I found it interesting. This is such a beautiful topic that me and my friends are talking about. Thanks for this blog, we are enlightened
RispondiEliminaIt works with me using ubuntu unity 12.04. Thanks a lot.
RispondiEliminaTnx ithel me alot... visit this site also.. you can learn more "HERE" Btw I like your site,,,. Good luck
RispondiEliminaThe blog is absolutely fantastic. Lots of great information and inspiration, both of which we all need. Thanks.
RispondiEliminawhy the command "sudo service tomcat7 start" not working with this setting????
RispondiEliminaThank a lot for sharing such all this !! It works and make it easy the installation process!!
RispondiEliminaBest Regard's,
Ben Linus,
Click On My Link Nitrotek.nl
Muchas Gracias por la guía, me sirvió mucho :D
RispondiEliminayou are in reality a good webmaster. The web site loading pace is incredible. It seems that you are doing any distinctive trick. Also, The contents are masterwork. you’ve performed a excellent job on this topic!
RispondiEliminaI've finally caught some music out in the States! This is really exciting.Download Delta Force Xtreme 2 Game | Download Commandos 3 Game | Download Call Of Duty Modern Warfare 3 Game
RispondiEliminaThis is a excellent blog, would you be involved in doing an interview about just how you designed it? If so e-mail me!
RispondiEliminaRyan Gosling Drive Jacket
I just now read something simular to this on That Are i believe they may of stolen the blog?
RispondiEliminaThank you, have recently been searching for information about this topic for long time and yours is the best discovery so far.
RispondiEliminaOver protect "The Clark Kent Superman Leather Smallville Jacket" is available in all size.
RispondiEliminaThanks for sharing this great Post dude
RispondiEliminaSEO Company bangalore
hi.. Its 3 a.m. and i was fighting with tomcat6 from last 3 hours. But thanks to you that i solved my problem by just purging tomcat6 and freshly installing tomcat7 in just 10 minutes. Thanks. (yawn)
RispondiElimina