How-To Geek
Installing Tomcat 6 on Ubuntu
If you are running Ubuntu and want to use the Tomcat servlet container, you should not use the version from the repositories as it just doesn’t work correctly. Instead you’ll need to use the manual installation process that I’m outlining here.
Before you install Tomcat you’ll want to make sure that you’ve installed Java. I would assume if you are trying to install Tomcat you’ve already installed java, but if you aren’t sure you can check with the dpkg command like so:
dpkg –get-selections | grep sun-java
This should give you this output if you already installed java:
sun-java6-bin install sun-java6-jdk install sun-java6-jre install
If that command has no results, you’ll want to install the latest version with this command:
sudo apt-get install sun-java6-jdk
Installation
Now we’ll download and extract Tomcat from the apache site. You should check to make sure there’s not another version and adjust accordingly.
wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz
tar xvzf apache-tomcat-6.0.14.tar.gz
The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat, but you could move it somewhere else if you wanted to.
sudo mv apache-tomcat-6.0.14 /usr/local/tomcat
Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose.
The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect.
vi ~/.bashrc
Add the following line:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder.
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 vi /etc/init.d/tomcat
Now paste in the following:
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pidexport JAVA_HOME=/usr/lib/jvm/java-6-sun
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
You’ll need to make the script executable by running the chmod command:
sudo chmod 755 /etc/init.d/tomcat
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/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
Tomcat should now be fully installed and operational. Enjoy!
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (124)
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 10/11/07




I think another part of this install (probably for any app that generates logs) is to add an entry to logrotate. Otherwise you get gobs and gobs of logs, especially on a production machine. Don’t ask me how I know this. I just know it. (/me hangs head in shame)
How about an article about logrotate?
Great suggestion! Will add it to the queue…
Thanks for the how to: It worked flawlessly, and I just upgraded to Gutsy Gibbon last night. For some reason, I hadn’t been able to get Tomcat to work for awhile now, and I found this article today. Thanks again. If it weren’t for people who go out of there way to share this kind of knowledge, I would have never discovered the wonderful world of Linux and Open Source technology. Thanks again.
Steve
Hi there, thanks for your great tutorial. But I am having a little problems.
1. NoClassDefinition: When I want to shutdown tomcat. It always gives me that error. But when i startup there are no problems at all.
2. After I followed all your instructions. How do I know if the installation works? I tried moving to http://10.0.106.21/ (which is the IP address of the server), Tomcat does not seem to load, I got a 404 error. Any idea why is this so?
Thanks
aaron
@aaron:
1. Does it say which class it can’t find? Can you post your full stacktrace? That’ll help track down the problem.
2. Try http://127.0.0.1:8080 to view it after it’s running. It doesn’t run on port 80 by default.
I have the same problem that Aaron has. JRE and JDK are installed and the variables are set.
~ sudo /opt/apache-tomcat/bin/catalina.sh run
Using CATALINA_BASE: /opt/apache-tomcat
Using CATALINA_HOME: /opt/apache-tomcat
Using CATALINA_TMPDIR: /opt/apache-tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun
Exception in thread “main” java.lang.NoClassDefFoundError:
I don’t know how to get full stacktrace. Any help is much appreciated.
Dan
You logs should be in /usr/local/tomcat/logs/ if you used the directions above. Looks like yours will be in /opt/apache-tomcat/logs.
There should be a file named localhost.YYYY-MM-DD.log in there (where YYYY-MM-DD is the year, month, day respectively).
Peruse that file and there should be a stack trace in there.
If there isn’t, do the following from the command-line:
> cd /opt/apache-tomcat/logs
> grep -l Exception *.log
That should list all the files that have a stack trace in them. Look at those files and it should say where the error is occuring.
HTH,
SETH
Thank you for your help but i can’t find any of these log files.
The folder /opt/apache-tomcat/bin/log/ is empty and in /opt/apache-tomcat/logs/ is only one file catalina.out. In catalina.out is only one line Exception in thread “main” java.lang.NoClassDefFoundError:
Is there a way get more information out of tomcat. That stacktrace, if that is one, seems not very helpful.
Dan
Weird. It’s not even finding the Bootstrap class to start Tomcat. I thought the error was happening further down the chain.
Add the following line to catalina.sh:
echo “CLASSPATH: $CLASSPATH”
it should go around line 232 after the “run” command check
elif [ "$1" = "run" ]; then
shift;
### NEW COMMAND ON NEXT LINE
echo “CLASSPATH: $CLASSPATH”
Send the output along. That’ll help find the problem.
I got the following line
CLASSPATH: :/opt/apache-tomcat/bin/bootstrap.jar:/opt/apache-tomcat/bin/commons-logging-api.jar
The bootstrap.jar is where it suppose to be but the commons-logging-api.jar is nowhere to be found on my system. Can this cause the problem?
Not having the commons-logging-api.jar shouldn’t matter unless you’ve configured something from the default.
What happens when you run:
javap -classpath “/opt/apache-tomcat/bin/bootstrap.jar” org.apache.catalina.startup.Bootstrap
It should print out the methods of the class.
That works.
~ javap -classpath “/opt/apache-tomcat/bin/bootstrap.jar” org.apache.catalina.startup.Bootstrap
Compiled from “Bootstrap.java”
public final class org.apache.catalina.startup.Bootstrap extends java.lang.Object{
protected static final java.lang.String CATALINA_HOME_TOKEN;
protected static final java.lang.String CATALINA_BASE_TOKEN;
protected java.lang.ClassLoader commonLoader;
protected java.lang.ClassLoader catalinaLoader;
protected java.lang.ClassLoader sharedLoader;
public org.apache.catalina.startup.Bootstrap();
public void init() throws java.lang.Exception;
public void init(java.lang.String[]) throws java.lang.Exception;
public void start() throws java.lang.Exception;
public void stop() throws java.lang.Exception;
public void stopServer() throws java.lang.Exception;
public void stopServer(java.lang.String[]) throws java.lang.Exception;
public void setAwait(boolean) throws java.lang.Exception;
public boolean getAwait() throws java.lang.Exception;
public void destroy();
public static void main(java.lang.String[]);
public void setCatalinaHome(java.lang.String);
public void setCatalinaBase(java.lang.String);
public static java.lang.String getCatalinaHome();
public static java.lang.String getCatalinaBase();
static {};
}
I downloaded Tomcat 5.5 and it works just fine right out of the box. That is weird.
Thanx man…i tried Tomcat6.0.14 with above instruction.It worked 100%
Great article. Some additional pieces of the puzzle:
chmod +x ./bin/*.sh
Error messages such as this are fixed with the above command:
“The BASEDIR environment variable is not defined correctly”
And Tomcat 6.0.14 runs on :8080 and not :8180
I’ve tried this tutorial to Xubuntu 7.10 with apache2.
It’s working….100%
This is a great tutorial…..thanks
I’m a newbie to Linux. This article was excellent! Thank you.
Hey guys – cool howto, but one question remains – now tomcat starts as root. How can i change it to let it run as different user?
tomcat is runing ok, but, i cant open http://localhost:8080/manager/html, how to configure tomcat’s users?
Thanks for the article.
Haven’t tried i yet but I’m sure it works. I have a question though.
How do you set up two different tomcats, e.g. one dev and one prod, on the same computer to autostart? Is it just do create two different scripts in init.d? Like tomcat-dev and tomcat prod and have them point to their respective environments?
Gustavo, in CATALINA_BASE/conf/tomcat-users.xml, add the following lines
restart tomcat and launch http://localhost:8080/admin
hmm, the lines were removed when posting, trying again
<role name=”admin”/>
<user name=”admin” password=”deep_dark_secret” roles=”admin”/>
Thanks for the article!
However, instead of creating the symlinks by hand you should take a look at “update-rc.d”…
How would I unstall it?
“you should not use the version from the repositories as it just doesn’t work correctly.” -= all very well when you wrote this. Please note this article was written in October of 2007. Ubuntu is ever being updated. new release is out, Hardy Heron 8.04 !
Maybe this Tomcat you speak of will work now.
@Terry
Good point… I’m going to test that out and see if the repo version works correctly. This guide is still relatively useful if you wanted to do a manual install, of course.
@Terry
The default installation of Tomcat5.5 from the repos in 8.04 is borked. I followed the instructions above and have TC6.0.14 running perfectly thanks to The Geek :)
@Mark
Thanks for testing that out, I hadn’t had a chance… glad it worked for you :)
Hi,
Thanks for the howto – very straightforward and pretty idiot -proof, which doesn’t say much for me as I have a slight problem :)
I set everything up, and all went well. I had cause to restart my machine over the weekend, and tomcat started automatically, great stuff so far. The problem occurs when I need to restart Tomcat having updated classes. The log files are created using the ‘root’ user (so owner and group is root), so I get a ‘permission denied error when tomcat tries to access them if my normal user executes the ./shutdown script.
Can you tell me how to change things so that, when starting the machine, tomcat runs under the regular user, rather than under root? Or is that not a good idea?
Thanks,
Micheál
The argument to dpkg in the first step should be –get-selections (two dashes)
Tomcat is not starting automatically even I followed the last steps necessary for making it starting at startup.I have to manually starting it up.
I have the same issue like Abhi and it runs under root, which I don’t like.
Hi,
I’m struggling with setting up TOMCAT 6 for more than two months now …no succes.
I have reinstalled UBUNTU from scratch, installed java and tomcat but it always gos wrong when I want to startup TOmcat. I have followed al the howtos tutorials forums in the net.
2 questions:
1° does it matter when I installed apache at UBUNTU-installation? Should I maybe chose a clean UBUNTU install and add apache-tomcat (and MySQL) later.
(PS. apache is running after UBUNTU LAMP instalation)
2° if that doesn’t matter how can it be that when $echo JAVA_HOME returns a correct value … that sh startup.sh in most case tells me that JAVA_HOME or JRE_HOME is not set. Actually without changing anything wuring my session I have seen succesfull startups (that is without above mentioned error message) but with the following error message : can’t touch CATALINA_HOME..pathegoeshere…/logs permission denied.
In any case the result is the same …nothing on http://serverIPadress:8080
(If I don’t get it to work before 15 june I will need to migrate (back) to Windows…no problems there!)
OK, so I did install Tomcat and it worked but…
The autostart part is not correct because Tomcat behaves differently when it autostarts.
More specifically Tomcat (or Java fails) converts all non-ascii characters to “?” when accessing anything on the file system. It will be impossible to open file “/home/user/ąžuolas.png” from any servlet as Tomcat (or Java) will look for file named “/home/user/??uolas.png”.
What is interesting is that once you restart Tomcat (sudo /etc/init.d/tomcat restart) everything will work fine. I do not know much about Linux internal workings but i looks like Tomcat is started before system locale is set. Unfortunetly I do not know how to fix this. Maybe somebody can help with this?
hi every body
thanks for the cool how to.
I followed up every single step. but it seems so wierd for me :
I opened firfox and put “http://localhost:8080/ and I got 401 Page not found error, bassically I expect the homepage of the tomcat installation
but if tried the following linke http://localhost:8080/manager/html
I get a login dialog box asking for a user name and password, what should I put here?
looking forward to your help
FYI: On hardy (8.04) at least, you can run the following command after creating your tomcat startup script in /etc/init.d in order to put links in the right spots.
update-rc.d tomcat defaults
tomcat is runing ok, but, i cant open http://localhost:8080/manager/html
8.04 server seemed to work pretty well. I was able to get it going by following some directions here…
http://blixtra.org/blog/2006/07/14/setting-up-tomcat-5-on-ubuntu-606/
I changed up all uses of “vi” to “sudo gedit” cause I am too newbie to be comfortable with vi, and I was having permissions problems.
had a moment of fear that I screwed up when I went to http://localhost/ but read the RUNING.txt and realized I should use http://localhost:8080/
thanks for the step by step!
Hi there,
nice article, but it leaves one nasty thing open, just as “me” already noted: Tomcat will run as root if you use your script, which is “working”, but not “what you want”.
Instead, make sure, the unprivileged user “tomcat” (or whatever you like) exists and start it using
sudo -u tomcat sh /usr/local/tomcat/bin/startup.sh
…
You might want to chown temporary directories prior to that, especially if you already ran tomcat as root:
cd /usr/local/tomcat/
chown -R tomcat webapps temp logs work conf
Actually, I don’t particularly like opening the conf directory for tomcat, but sometimes tomcat prefers to write to its configuration… You don’t need webapps to belong to tomcat if you dont autodeploy, but you definitely need logs and work.
Unlike Mark, I get the same issue as Mario:
startup.sh says that “Neither the JAVA_HOME nor the JRE_HOME environment variable is defined”, but when I enter “echo $JAVA_HOME” or “echo $JRE_HOME” I get “/usr/lib/jvm/java-6-sun”
(Ubuntu 8.04 64bit, Tomcat 6.0.14)
But unlike Mario, I can not migrate back to Windows. I’m dead in the water…
…so now I’m “undead”?
Regarding Tomcat’s inability to see the enviroment’s JAVA_HOME variable: here’s what worked for me:
http://ubuntuforums.org/showthread.php?t=819451&page=2
Problems!
I can’ t set CLASSPATH!!
I’ve tried many ways, but nothing has worked for me.
$ javac -classpath “/usr/loca/tomcat/lib/servlet-api.jar” HelloWorldExample.java
HelloWorldExample.java:23: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorldExample.java:24: package javax.servlet.http does not exist
import javax.servlet.http.*;
I’ve tried to put this classpath in “etc/profile”, in “~/.bashrc”, to load it in a sh script at init.d…
Tomcat works fine under netbeans 6.1, compiling, etc. It just happens on bash.
Any Ideas?
Hi I followed all the steps but i wasn’t able to find the /etc/rc2.d/S99tomcat. I dont have this file. i created everything else mentioned here. im stuck here and i have been trying desperately to install tomcat on my ubuntu7.10 laptop. could any one lend any help, please?
Hi Teena. You must have missed the very last step, which was to create the symbolic link you are asking about using the “sudo ln” command. Have another look at the instructions.
Hi Amos,
when i tried to create that last step i got the error saying the S99toimcat file/directory cant be found.
this is the only step im having problem with. i did all the steps correctly.
Thanks,
Teena
Hi Teena. The last step is:
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
which *creates* the S99tomcat link to the /etc/init.d/tomcat file you created in an earlier step. I have no idea how running that command as written could create the error you are describing. Even if neither of those files existed, the command would still run and create the link to a non existent file. Are you sure you are typing in the command “ln” and not “ls”? Did you try copying and pasting that whole line off the page into your terminal?
Dear Amos,
I installed Tomcat 6.0.14 on my Ubuntu7.10 yesterday after a lot of struggel :)
Thanks so much for your support. I didnt actually execute the last step this time. since im a newbie to linux, i made many mistakes while installing tomcat. i think its not necessary to create these symlinks if i do not want to start the server automatically at start up.
Thanks a lot,
Teena
Congrats Teena. It’s not as nice and easy a process as it could be, that’s for sure. Startup scripts seem to be the achilles heel of server applications that aren’t packed for a particular distribution. So many must get written and customized for particular distributions but so few seem to get submitted back for inclusion in the core distributions.
Hello,
Tomcat does not work well when installed from the repository, that’s true, but the fix for this is not too complicated (at least if you insist on using the package):
First install the package (note that you should match your tomcat version with your java version, and I’ve not come around to update my server, so this pertains to java 5 with tomcat 5, however I suspect the procedure for fixing tomcat 6 with java 6 should be similar to this).
In the file /etc/default/tomcat5 uncomment and set up JAVA_HOME (see above for the path, but note that if you do not use java 6 and tomcat 6 you should change it to look something like “/usr/lib/jvm/java-1.5.0-sun”), also make sure the following line is uncommented (in the same file):
TOMCAT5_SECURITY=no
This will turn off jaas-security. This is what makes tomcat impossible to use out of the box.
You may also wish to set up the -tag since it’s set up, per default to open tomcat at port 8180. You do this in /etc/tomcat/server.xml like this (note the port-attribute, and the number, you can probably alter the existing -tag, just make sure you have the right one — check the comment!):
That way you should get tomcat 5 from the repositories to work. I’m guessing jaas is turned on as some kind of precaution against getting sued or something, and why the JAVA_HOME variable isn’t reflected by the update-java-alternatives command is beyond my understanding.
Cheers!
P.S. I foolishly used XML syntax for describing the update of the server.xml file. (I’ll give it another try):
You may also wish to set up the Connector-tag since it’s set up, per default to open tomcat at port 8180. You do this in /etc/tomcat/server.xml like this (note the port-attribute, and the number, you can probably alter the existing Connector-tag, just make sure you have the right one — check the comment!):
<!– Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 –>
<Connector className=”org.apache.coyote.tomcat5.CoyoteConnector”
port=”8080″ minProcessors=”5″ maxProcessors=”75″
enableLookups=”true” acceptCount=”10″ debug=”0″
connectionTimeout=”20000″ useURIValidationHack=”false” />
That way you should get tomcat 5 from the repositories to work.
By the way, you may also want to check the update-rc.d command in Debian/Ubuntu, with it you can make the init-script set up automatically. Unfortunately not the actual script, but the linking and such.
Hello,
I followed your instructions (thanks for doing this) and was able to install Tomcat 6.0.18 on Ubuntu 8.04 to the point where I get the index.html page displayed when I go to http://localhost:8080 . However, it seems none of the relative links are reachable from the top level page (e.g. http://localhost:8080/docs). It just spins waiting for localhost until it times out.
$CATALINA_HOME is set to /usr/share/tomcat (as is $CATALINA_BASE, by default), but if /usr/share/tomcat/webapps/ROOT is the root directory where the index.html page is found, one would expect http://localhost:8080/docs to resolve to the path /usr/share/tomcat/webapps/ROOT/docs . However, the docs directory is to be found at /usr/share/tomcat/webapps/docs .
Can someone please tell me what I need to do to fix this and complete the installation?
Hi,
It was a great thing to setup Tomcat6.0.18 on my Ubuntu Machine. Thats a lot for this awesome documentation.
I ran startup.sh from the /usr/local/tomcat/bin folder. The below are the outputs which I was getting.
nikon@Stunning:/usr/local/tomcat/bin$ ls start*
startup.bat startup.sh
nikon@Stunning:/usr/local/tomcat/bin$ startup.sh
bash: startup.sh: command not found
nikon@Stunning:/usr/local/tomcat/bin$ ksh
$ startup.sh
ksh: startup.sh: not found [No such file or directory]
$ ls -l startup.sh
-rwxr-xr-x 1 nikon nikon 1956 2008-07-21 20:01 startup.sh
I was able to http://127.0.0.1:8080/ get this page loaded. “If you’re seeing this page via a web browser, it means you’ve setup Tomcat successfully. Congratulations!” Not sure how this came as the startup.sh didn’t work correctly.
I tried clicking on the Admistration/Status http://127.0.0.1:8080/manager/status. It said Page Load Error (Firefox can’t establish a connection to the server at 127.0.0.1:8080.)
Can anyone help me on this.
Out of curiosity, I installed Ubuntu and Java/Eclipse and wanted to install Tomcat and the mySQL too.
The howto’s okay and the startupscript is okay, but the tomcat’s running on port 8080 and does not interact with – for example – an existing Apache 2, no logrotation and so on…
Maybe I’ll write a howto about those issues next.
@stunningnikon: you can’t start a shellscipt by typing it’s name as long as the script does not reside in a directory which is in the path of your shell you are using. The correct syntax of starting scripts is /path/to/the/script/shellscript.sh
If you are ‘sitting’ in this directory type ./shellscript.sh or bash shellscipt.sh – however…
What the hell are you trying to install Tomcat, Java/Eclipse and MySQL for?
Just try to learn basics first, Java is an extremly hard entry point if you want to start hacking, in my opinion.
Regards,
Steffen
Thanks a lot! The instructions were perfect. I appreciate it.
Cheers!
–Vik
—-Of All The Things I Have Lost… I Miss My Mind The Most
errors;
dpkg –get-selections should be dpkg –get-selections
this address;
wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz
should be this;
wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
so this
tar xvzf apache-tomcat-6.0.14.tar.gz
will be this;
tar xvzf apache-tomcat-6.0.18.tar.gz
of course using tab key you dont have to change all of that…
sudo mv apache-[tab] /usr/local/tomcat
I know in Zope for instance you have to create a user called zope and give it rights to its own directories, Never use ROOT to do zope’s job (run scripts etc.) So in case of tomcat may be there should be a user admin who haws rights to tomcats files/folders?
I am not really sure about that!?
thank you for the tutorial,
but there is a small error :
it should be
dpkg –get-selections | grep sun-java
instead of
dpkg –get-selections | grep sun-java
Note that tomcat6 is now available as an official Ubuntu package (starting from 8.10 release) so this whole howto could be replaced by “sudo apt-get install tomcat6″.
After setting up tomcat. this is what i get on start up
Using CATALINA_BASE: /usr/share/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun:.
touch: cannot touch `/usr/share/tomcat6/logs/catalina.out’: No such file or directory
/usr/share/tomcat6/bin/catalina.sh: 357: cannot create /usr/share/tomcat6/logs/catalina.out: Directory nonexistent
sorry am new to apache. how do i solve this
be sure that you have a directory /usr/share/tomcat6;
if you have this directory, you can try to make the directory logs under /usr/share/tomcat6 by
mkdir /usr/share/tomcat6/logs
i am trying to run the Halloworld program andthis is wat i get
The requested resource (/jjolt/servlet/HelloWorld) is not available
on shutdown this is the responce i get
how do i solve either of this
Using CATALINA_BASE: /home/developer/Documents/apache-group/apache-tomcat-6.0.18
Using CATALINA_HOME: /home/developer/Documents/apache-group/apache-tomcat-6.0.18
Using CATALINA_TMPDIR: /home/developer/Documents/apache-group/apache-tomcat-6.0.18/temp
Using JRE_HOME: /usr
developer@developer-laptop:~$ shutdown.sh
Using CATALINA_BASE: /home/developer/Documents/apache-group/apache-tomcat-6.0.18
Using CATALINA_HOME: /home/developer/Documents/apache-group/apache-tomcat-6.0.18
Using CATALINA_TMPDIR: /home/developer/Documents/apache-group/apache-tomcat-6.0.18/temp
Using JRE_HOME: /usr
java.lang.NoClassDefFoundError: org/apache/tomcat/util/log/SystemLogHandler
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2406)
at java.lang.Class.getConstructor0(Class.java:2716)
at java.lang.Class.newInstance0(Class.java:343)
at java.lang.Class.newInstance(Class.java:325)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:218)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:390)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.log.SystemLogHandler
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
… 7 more
i am not sure but with tomcat 6.0.18, i don’t need to set JAVA_HOME in bashrc file. Just moving to tomcat/bin and type ./startup.sh
I have to install Tomcat as a part of a Tafe assignment but I don’t really know anything about it so how do I test to see if it is running. I tried ps -A but I can’t see any process named tomcat or anything similar.
Thank you very much for writing this, I was able to follow the instructions and get it setup in a few minutes. One thing that might be worth adding is the need to enable multiverse repository (for installing sun-jdk6)
thanks for the article- that was almost too easy.
I am running tomcat6 on ubuntu which I downloaded as part of bitnami’s redmine stack. When I go to 127.0.0.1:8080, Tomcat’s welcome pops up. The docs & examples are loaded correctly. I added a “manager” and an “admin” to the tomcat-users.xml file as instructed. I restarted tomcat6 and I am still unable to log in to either the manager webapp or the host-manager webpapp with the user ID and password that I entered into tomcat-users. It gives me a continual loop of requesting the id and password until I hit cancel. Help!
gettica,
Make sure you removed the comments from the tomcat-users.xml file.
(remove the on the line before the statement.
gettica,
Make sure you removed the comments from the tomcat-users.xml file.
(remove the statement and the – - > on the line before the statement.
Hi there,
It just worked. Precise instructions particularly to me :)
Hi,
I’m trying to run a Java web application on localhost. Op sys: Ubuntu, Tomcat 6.0.
I installed tomcat 6.0 under /usr/share/tomcat6 and tried to direct /etc/init.d/tomcat6 (as far as I know this is what starts the tomcat on startup) to start the tomcat from /usr/share/tomcat6/bin.
When I start my computer the tomcat runs and I can see default page, but when I try to vist my app page I get Nullpointer on MySQL connection close().
But if I shutdown tomcat (using /etc/init.d/tomcat6 stop) and restart the tomcat directly from /usr/share/tomcat6/bin startup.sh. Then everything works fine.
So basically with command “/usr/share/tomcat6/bin/startup.sh” I can see my app, but with command “/etc/init.d/tomcat6 start” I can’t. Allthough both of them start tomcat.
I want that I can see my app right after computer stars (so I don’t manually have to start tomcat).
Can anybody help?
Regards,
Risto
Already got it fixed.
flawless! thank you :D and you are just very correct about not installing from ubuntu archives, they screw the manager and the host-manager..
hey the option for dpkg is –get-selection which is
(double hyphen)get(single hyphen)selection
do you think you guys can make it more clear?
enjoying your site a lot-pretty useful, thank you!
Do you know if runlevels have changed in Jaunty? I cannot get the script to start automatically, even though it’s been working fine in previous versions. It starts fine in a terminal, just not on computer startup.
I can’t agree olaf no more. He really saves my life in starting up tomcat as unprivileged user.
What’s more I start up tomcat by using djb daemontools, here comes the commands and scripts:
useradd tomcat -g nogroup -d /java/tomcat6/ -s /bin/false -p’*’ -r
useradd tomcatlog -g nogroup -d /tmp -s /bin/false -p’*’ -r
cd /java/tomcat
chown -R tomcat webapps temp logs work conf
mkdir -p /var/service/
cd /var/service/
mkdir -m 1755 tomcat
cd tomcat
vim run
———————————————
#!/bin/sh
exec 2>&1
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_OPTS=”-Xmx1024M -Xms256M -server”
export TOMCAT_HOME=/java/tomcat6
echo “*** Starting tomcat…”
exec setuidgid tomcat ${TOMCAT_HOME}/bin/catalina.sh run
———————————————–
chmod 755 run
mkdir -m 755 log
chown tomcatlog:nogroup log
cd log
wget -O run http://qmail.jms1.net/scripts/service-any-log-run
vim run
——————————————–
VQ=”/var/qmail”
exec env – PATH=”$VQ/bin:/usr/local/bin:/usr/bin:/bin” \
setuidgid tomcatlog multilog t n1024 s1048576 ./main \
‘-*’ ‘+*ver: status:*’ =lstatus
————————————————
chmod 755 run
/etc/init.d/tomcat stop
ln -s /var/service/tomcat /service/tomcat
sleep 5
svstat /service/tomcat/ /service/tomcat/log/
I am not sure if this has been covered in an earlier post, but the way given to set up the tomcat-users.xml file did not work for me.
This did, however:
The role tags were added automatically when I restarted the server, but I don’t know if this will happen for everyone, so I am leaving them in.
-Bucky24
it left out the xml tags….
Oh well, I can’t get it post the tags…
http://www.netadmintools.com/art340.html
Here is the site I found that gave the correct usages.
Whoever is using Netbeans IDE on Ubuntu, don’t try to install Tomcat6 that comes with Netbeans distribution! This is the right way to install Apache-tomcat6. Thanks to the author!
It took me forever to find the answer to fix autostart on ubuntu 9.04.
Here it is:
1. First remove old symlinks with sudo update-rc.d -f tomcat remove
2. Execute the follwoing: sudo update-rc.d tomcat start 99 2 3 4 5 S . stop 0 1 6 .
Credit goes to dumb.coder at http://ubuntuforums.org/showthread.php?t=1188880&highlight=tomcat+autostart
great work……its really helpful
Isn’t Tomcat in the repositories? I’m using Jaunty and a simple sudo-apt get install tomcat6 did the job for me!
Thank you very much!, This how to has proven to be extremely useful.
Hi, thank’you very much for this tutorial.
It saved my life! I had some jsp apps connecting to a MySQL db that just did not work with tomcat6 package from ubuntu repos!!! Now they work flawless! This also applies to Karmic, not just to Jaunty.
Just for my curiosity: is tomcat6 from ubuntu a free implementation of tomcat 6 specifications or it is just the official apache tomcat app packaged for ubuntu?
If not, wouldn’t be a good idea to create a ppa for the latest Apache Tomcat 6 from official site?
Wow alberto, I needed that link too. For some reason tomcat wouldn’t even start manually installing it the way described here but with your link to ubuntuforums it autostart and everything thanks! My ubuntu version is 9.04.
Also, from the ubuntuforums: “it took me days, but I finally realized that tomcat will only start during boot if the startup script is in /etc/rcS.d .. When the start-up script is in /etc/rc2.d – The script doesnt give any errors, and the tomcat logs do not indicate any problems .. its like the process just poofs.”
http://ubuntuforums.org/showpost.php?p=7583672&postcount=3
An update to this tutorial is overdue I guess.
Thank you…i watched out for this solution for 3 days of work…THANKS!!
Comfreak
AMAZING!
I’ve been trying to figure out how to install Tomcat on Ubuntu for a long time, and this is just the step-by-step tutorial I was looking for! Worked the first time! Thanks!
Thank you very much. My pc died and I decided to switch to ubuntu on my new laptop. Installed myEclipse, but the tomcat6 wouldn’t work. I really appreciate making this information available. Did notice a few changes from tomcat5.
thanks again.
There’s a better workaround so you can keep Ubuntu’s Tomcat6 (taken from http://ubuntuforums.org/showthread.php?p=8541057, by DisDis)
In a terminal:
1. sudo apt-get install tomcat6
2. cd /usr/share/tomcat6
3. sudo ln -s /var/lib/tomcat6/conf conf
4. sudo ln -s /etc/tomcat6/policy.d/03catalina.policy conf/catalina.policy
5. sudo ln -s /var/log/tomcat6 log
6. sudo chmod -R 777 /usr/share/tomcat6/conf
sudo apt-get install tomcat6 cd /usr/share/tomcat6 sudo ln -s /var/lib/tomcat6/conf conf sudo ln -s /etc/tomcat6/policy.d/03catalina.policy conf/catalina.policy sudo ln -s /var/log/tomcat6 log sudo chmod -R 777 /usr/share/tomcat6/conf
There. Now just go to Window/Preferences/Sever/Runtime Environments, add the Apache Tomcat6 Server and use /usr/share/tomcat6 as the installation directory!
my tomcat is configure but the default web directory is $CATALINA_HOME/webapps/ROOT/index.html
i want to change the directory to $CATALINA_HOME/webapps cant someone help me tnx
you may read the tomcat documentation?
webapps/ROOT/index.xhtml is actually the file you see when you dont use a context (http.//host/index.xhtml)
this is the ROOT context.
If you dont want to have it in webapps/ROOT you can place a ROOT.xml context file in tomcat/conf/Catalina/localhost/ROOT.xml and let tomcat know in which directory or .war file the root context resides.
(just in case)
Tank you tank you tank you very nice tutorial, easy.
i have problem in starting up the server
when i issue this command
sudo /etc/init.d/tomcat start
…..
i got this …
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
touch: cannot touch `/usr/local/tomcat/logs/catalina.out’: No such file or directory
/usr/local/tomcat/bin/catalina.sh: 448: cannot create /usr/local/tomcat/logs/catalina.out: Directory nonexistent
……….
Any help PLZ, i got confused :(
Dear Author
Nice Article, but if you follow the steps that you given are not working fine w/ U-9.10.
Regards
Amit Pandya
Look for Tomcat on Synaptic Package Manager.
It’s that simple.
Thanks a lot. I worked flawlessly for me!
so how do you start or stop the tomcat server?
Thank you! Your instructions were simple and worked flawlessly with Tomcat 6.0.29 on CentOS 5.4.
Works fine!
But Tomcat runs as”root”. How to run it under user “tomcat”?
Ok, Googling is great!
I found another script. It also works fine and starts tomcat using user tomcat. You just need to make sure you have a user “tomcat”.
Cheers & have fun!
#!/bin/bash
#
# tomcat
#
# chkconfig:
# description: Start up the Tomcat servlet engine.
RETVAL=$?
CATALINA_HOME=”/opt/apache-tomcat-6.0.29″
case “$1″ in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $”Starting Tomcat”
/bin/su tomcat $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $”Stopping Tomcat”
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $”Usage: $0 {start|stop}”
exit 1
;;
esac
exit $RETVAL
Thank you very much for this tutorial,
There is one problem here,
the url http://localhost:8080/ works fine but when I try to access to the link Tomcat Manager, I don’t find the right username/password,
have you any idea of this
Thanks
Really helpful. Simple yet effective.
Thanks!
Anyone tried this on ubuntu lucid with tomcat 7?? im going to try installing it
anyway i want to put tomcat 7 working with netbeans 6.9.1 , they told me netbeans can start the server so i dont have to create the startup?? how do i unlink the simbols? do i only have to copy it to my folder to make it work with netbeans?
ok i got it working…but how do i remove the auto start up and the links to the symbols?
This is crazy! The tomcat6 package from the Ubuntu repository works flawlessly on Ubuntu 10.04.
$ sudo aptitude install tomcat6
DONE!
@hDave
Hi, I have installed tomcat6 like you. But now I can’t find catalina.sh Usuali it is in /usr/local/tomcat/bin/catalina.sh
Can you maybe tell me where I can fint it now?
Thanks!
Elf
@Anis
Thank you very much for this tutorial,
There is one problem here,
the url http://localhost:8080/ works fine but when I try to access to the link Tomcat Manager, I don’t find the right username/password,
have you any idea of this
Thanks
You can fix that problem if you configure /usr/local/tomcat/conf/tomcat-users.xml file. You have to uncomment the next piece:
[Disregard my last comment; it doesn't work; I can open the "examples" index but the examples themselves don't work and I don't know why]
First Thank you very much.
Installing Apache Tomcat/7.0.8
dpkg –get-selections | grep sun-java
This should give you this output if you already installed java:
sun-java6-bin install
sun-java6-jdk install
sun-java6-jre install
If Java is not installed then install java and proceed.
Install Sun Java.
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update
sudo apt-get install sun-java6*
Install Tomcat – First Install java.
wget http://ftp.wayne.edu/apache/tomcat/tomcat-7/v7.0.8/bin/apache-tomcat-7.0.8.tar.gz
tar xvzf apache-tomcat-7.0.8.tar.gz
sudo mv apache-tomcat-7.0.8 /usr/local/tomcat
sudo gedit ~/.bashrc
@REM Add the following line to .bashrc after the last line.
export JAVA_HOME=/usr/lib/jvm/java-6-sun
@REM @Edit tomcat-users.xml with the following content.
sudo gedit /usr/local/tomcat/conf/tomcat-users.xml
@REM start the server
sh usr/local/tomcat/bin/startup.sh
@REM Open browser http://127.0.0.1:8080 or localhost:8080
server Status button, Manager App Button, Host Manager should work with xxUSER and yyPASSCODE
test JSP by going to this link
http://localhost:8080/examples/jsp/jsp2/simpletag/hello.jsp
@To Shutdown the Server.
sh usr/local/tomcat/bin/shutdown.sh
sudo gedit /usr/local/tomcat/conf/tomcat-users.xml
Great help. One of the best tutorials for installing tomcat. Clean and concise. Thank you so much
Hello help me pls, when I give this cmd in terminal I get the following error….
55@TP055:~/apache-tomcat-6.0.32/bin$ sh startup.sh
Cannot find ./catalina.sh
This file is needed to run this program
thanks, very nice
hi,
Thx for this HowTo it was so easy to follow it step by step but i have a problem :(
I have installed tomcat server on my computer (OS: ubuntu).
I tried since friday to deploy my first web application but there is the same error every time.
I made some research on internet and forums but i didnt find an answer.
So, somebody could help me it will be nice
sorry i forgot to post the stack trace:
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.JsonConfig
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
any ideas ??
al correr startup.sh para apache-tomcat-6.0.18
me manda el sig error.
Cannot find ./catalina.sh
This file is needed to run this program
me podrian ayudar cual es la causa por favor
@Carlos Silva
Hola Carlos. Lo que te ocurre es porque necesitas que los .sh tengan permiso de ejecución (-x). Para solucionarlo, puedes ejecutar el comando “chmod +x *.sh” estando en /apache-tomcat-6.0.18/bin/
Un saludo.
———————–
Hi Carlos. You need yo add execution perms to .sh files. To fix it you can execute command “chmod +x *.sh” being at /apache-tomcat-6.0.18/bin/
i am having problems properly setting JRE_HOME variable. i get this output:
michelle@SQA-2:/usr/local/tomcat/bin$ sudo ./startup.sh
[sudo] password for michelle:
Using CATALINE_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
i feel like that line “Using JRE_HOME: /usr” should definitely have more to it…and i added this line to the end of .bashrc
“export JAVA_HOME=/usr/lib/jvm/java-6-sun”
logged in and out…did everything and i still get the same output when i try and run tomcat…any clue??
i just added a new file in tomcat/bin with the line “JAVA_HOME=/usr/lib/jvm/java-6-sun”
now the output comes out but tomcat doesnt actually run…
now any ideas??
any help would be much appreciated
hi michelle,
stop your tomcat service and you only need to add this line:
JAVA_HOME=”/usr/lib/jvm/java-6-sun”
JRE_HOME=”/usr/lib/jvm/java-6-sun”
into /etc/environment.
and check your tomcat/bin directory, if there’s setenv.sh file exist then you must also put this line below into setenv.sh file:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
logout from that machine (reboot not needed) and run echo $JAVA_HOME it should be same as you defined above, tomcat is ready :)