Setting Up Tomcat 5 on Ubuntu 6.06 40

I had mentioned that I’d post a quick how-to on setting up Tomcat 5 on Ubuntu Dapper. So here it is and lucky for me it’s VERY easy.

Translations: castellano

First a quick overview of what we are going to do:

1. install software
2. change 1 line in a configuration file.
3. start the Tomcat5 service
4. go to http://localhost:8180

And now for the good stuff.

First we want to install the right packages. basically we want to install apache2, a java jdk and tomcat (duh). I’ve chosen to use Sun’s java implementation. To install this you need to enable the multiverse repository. See this section of the Unofficial Ubuntu Starter Guide for help with enabling additional repositories. To install Tomcat itself you will also need to have the universe repository enabled.

Note: For Tomcat you MUST have a jdk not just a jre.

So, for the basic install use the following command.

sudo apt-get install apache2 tomcat5 sun-java5-jdk

If you want a shiny Tomcat welcome page when we finally get that far then install the example apps by adding tomcat5-webapps to the end of the last command. For the Tomcat admin web interface add tomcat5-admin, too.

My final command looks like this.

sudo apt-get install apache2 tomcat5 sun-java5-jdk tomcat5-webapps tomcat5-admin

By default Ubuntu uses a free Java implementation. We now need to tell Ubuntu that we want to use Sun Java as the default. Run the following command.

sudo update-alternatives --config java

Then enter the number of the version of Java you want from the list when prompted. The one I wanted was /usr/lib/jvm/java-1.5.0-sun/jre/bin/java.

Now we need to tell Tomcat where the jdk is. Open /etc/default/tomcat5 and change the variable JAVA_HOME to read…


Make sure it’s NOT got a “#” at the start of the line. You can should now be able to start Tomcat5 with…

sudo /etc/init.d/tomcat5 start

Tomcat is listening on port 8180. So open up firefox and enter http://localhost:8180 in the address bar. Once the page loads you should see either a tomcat welcome page or, if you chose not to install the examples and admin packages, a fairly empty page with “Apache Tomcat/5.0″ at the bottom left. Congrats, you just installed a working Tomcat service. If you don’t see one of these pages, either you or I screwed up. ;)

If you installed them, the example apps can be found in “/usr/share/tomcat5/webapps/“. Also take a look at the configuration files in “/etc/tomcat5/“.

Hope that was helpful.

Update: Manolo Canga added a section in his Spanish translation of this tutorial that I’ve translated into English below.

Setting up an admin user

If you try to use the admin interface you’ll find you can’t because no admin user has been set up. To resolve that go into /var/lib/tomcat5/conf and edit tomcat-users.xml. You’ll see that 3 users have been created by default. We’re going to change the password of the user “tomcat” (<user username="tomcat" ) to something better than the default of “tomcat”. Duh!? Now we are going to give the user “tomcat” admin access. Add “admin” to the user tag’s roles attribute. It should look smilar to this.

<user username="tomcat" password="your_password" roles="tomcat,admin"/>

Now restart tomcat…

sudo /etc/init.d/tomcat5 restart

…and you’re done!

40 thoughts on “Setting Up Tomcat 5 on Ubuntu 6.06

  1. Reply Mark Jul 17, 2006 15:29

    Hm.. I get an error like:

    Could not create the Java virtual machine.
    dpkg: error processing sun-java5-bin (–configure):
    subprocess post-installation script returned error exit status 1
    Errors were encountered while processing:
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    Every time I try to install java. At first I thought it might be from too little Ram, but after bumping it up to 512MB I think the problem might be elsewhere.

  2. Reply Chris Jul 17, 2006 15:45

    First try…

    sudo apt-get -f install

    The try to install again.

    If that doesn’t work, I’d recommend you get some help on the ubuntu irc channel for that. It may be that if you’ve installed java before some files are still around and need to be over written.

  3. Reply Manolo Canga Jul 20, 2006 19:31

    Thank you, It’s is very good.
    A spanish translate ->

    Thank you again.

  4. Reply Chris Jul 21, 2006 00:03


    Thanks! I added a link a the top and translated your addition too. :)

  5. Reply Uche Aug 9, 2006 16:44

    I installed tomcat 5 according to the instructions and it did work fine with the sample pages. However when I deployed another jsp application, it gives me Error 404. I have checked everything seems alright.
    Thanks for your help

  6. Reply Tim Aug 18, 2006 00:21

    Great directions – installed without a hitch. Many thanks!

  7. Reply shashank bala Aug 23, 2006 00:25

    Great work … helped me easily set up tomcat on my ubuntu box! keep up the good work !

  8. Reply Patrick Sep 6, 2006 23:57

    Hi there,

    Great stuff. How can I integrate Tomcat with Apache (PHP)?

  9. Reply shrikant Sep 8, 2006 00:23

    plz give me suggetion about admin setup in tomcat

  10. Reply Jostein Sep 9, 2006 20:34

    very good! thanks

  11. Reply Casey Sep 25, 2006 19:05

    Excellent, excellent!

    This is the best tutorial on Tomcat 5 installation I have found..

    ONE QUICK NOTE: You must make sure that the Ubuntu Multiverse repository is added to the /etc/apt/sources.list file in order to install JVM/JDK:

    1. Add these lines to the file:

    deb dapper multiverse
    deb-src dapper multiverse

    2. Run “sudo apt-get update”

  12. Pingback: luKas' bloggie [at]

  13. Reply luKas Sep 25, 2006 19:54

    Thnks man, this is very usefull to me …..Thnks again …and good luck to you !

  14. Reply Piet Sep 29, 2006 13:41


    for one or another strange reason that I don’t find, I can’t startup Tomcat because there is no tomcat5 file in /etc/init.d. How does this happen? How can I install this file manually?


  15. Reply Chris Sep 29, 2006 16:44


    That would mean you do not have the package tomcat5 installed. Installing the software is covered at the beginning of the tutorial.

    You can enter…

    sudo apt-get install tomcat5

    …on the command line to install tomcat. If the package is already installed, it will say…

    tomcat5 is already the newest version.


  16. Pingback: » Re: Tomcat would start -

  17. Pingback: the rasx() context » Blog Archive » Installing Tomcat

  18. Reply Andi Oct 15, 2006 23:06


    this howto is great.
    However Im still facing a problem:
    System is intelbased, Kubuntu 6.06

    I did it all like discribed above. When I first started tomcat by init script just the normal text appeared but nothing started. After playing around, I found out that a line “JAVA_HOME=’/usr/lib/jvm/java-1.5.0-sun’” helps. Tomcat starts with the right java machine, but crashes after about 5 seconds.
    If Im very quick and call the http://localhost:8180 during the period the tomcat works, I can acces the standard pages.

    Did anyone have the same problems? Does anyone know what to do?


  19. Reply PedroB Oct 18, 2006 21:42


    Very Good howto about the ubuntu java instalation.
    I have read far too many mistifying info until I were able to solve/understand my problems.

    As a new linux user I must thank you for your effort in publishing this howto.

    Pedro B

  20. Reply JamesB Oct 31, 2006 17:10

    I followed your instructions and it worked great. However, when I put a war in the webapps folder it won’t auto unpack and deploy. When I use the tomcat manager to manually deploy a war I get a FAIL-Encountered exception Permission denied. Being a Linux newbie, I’m having trouble beginning to know what permission is being violated. I know that with the Tomcat5 for Ubuntu java security manager is turned on by default. I’ve tried monkeying with that, but to no avail. Did you encounter problems with that? If so I’d love to hear how you overcame the problem.
    Thanks in advance.

  21. Reply Olly Nov 8, 2006 12:56

    Great guide,

    Many thanks

  22. Reply Ubis Nov 11, 2006 11:47

    I get an empty page at http://localhost:8180 :-(
    any ideas?

  23. Reply Matthew Nov 20, 2006 21:24

    Thanks soooo much! So many different directions for so many freakin’ distros…this is what makes Linux so much harder than just rtfm! Anyway, thanks a lot for this!

  24. Reply Lam Dros Nov 27, 2006 02:50

    Very useful procedure to install tomcat5 on ubuntu 6.06. But I installed everything correctly on a Kubuntu but when I try http://localhost:8180 the browser does not respond until timeout expired. Can you help me. Is it problem of tomcat java or apache or the port is wrong.

  25. Reply JanErik Dec 19, 2006 11:11

    Can you explain why Tomcat answers on http://localhost:80 but not on http://localhost ?
    And in Kubuntu, am I supposed to manually have to create the user tomcat5.5? Now running Tomcat as root to be able to use port 80 though.

  26. Reply Mark Jan 4, 2007 05:41

    That’s a nice simple tute on getting Tomcat running on Ubuntu 6.06 and it works a treat.

    Like Patrick says, the next thing is to integrate it with apache2. There seem to be a number of ways of doing this and I can’t get a handle on which is the most correct way to go.

    Any pointers anyone?

  27. Reply danfolkes Jan 18, 2007 05:54

    Great tutorial. I got mine up and running with the quickness after reading this. Thank you beautiful community.

  28. Reply Mircea Feb 4, 2007 23:33


    for one or another strange reason that I don’t find, I can’t startup Tomcat because there is no tomcat5 file in /etc/init.d. How does this happen? How can I install this file manually?

    cheerz! ”

    Same problem here (reinstalling doesn’t help). Chris stop talking nonsense if you don’t know a solution.

  29. Reply Mr.ZooM Feb 13, 2007 23:38

    Great tutorial, it works fine with Debian Etch and Tomcat5.5 :-) Do you have a tutorial on how I configure tomcat with virtualhosts?

    Thanks a lot

  30. Pingback: YMind » Installazione e setup di Tomcat 5 su Ubuntu 6.06 Dapper

  31. Reply Pasquale Feb 13, 2007 23:52

    I made a translation and an adaptation in Italian language of this very very helpful and great article.
    Thanks and … very good job :)

  32. Reply tuniki Feb 16, 2007 23:40

    Great article!
    I am gonna suggest few things;
    1. Do not hard code JAVA_HOME in tomcat conf.
    2. No need to install apache2
    3. Default tomcat port is 8080 and not 8180

  33. Reply Steven G. Harms Aug 20, 2007 04:56

    Great tutorial. I thought I’d mention that you may want to put a caveat. I set my

    JAVA_HOME= some/path/here

    You may not notice the space after the equals sign? Yeah. That fouled up my kickoff. I was dumbfounded until I went for a walk and came back and it stared at me. Just a quick point to help the hasty and easily addled ;)


  34. Reply Joe Sweeney Aug 29, 2007 21:37

    These directions are fantastic! The only glitch I had was when I tried to edit the /etc/default/tomcat. I’m a newbie to Linux, so I forgot to specify sudo when I opened the file.

  35. Reply Daniel Orlowski Oct 9, 2007 11:11

    Works great, thanks!

  36. Reply Magnet Sep 4, 2008 15:34

    Ho i have jetty installed on the same system.I want to use both jetty and tomcat on the system any ideas on how i can do that?

  37. Reply sunil Sep 16, 2013 21:53

    It shows internal server error while accessing the JSP page after install Tomcat. Is that a problem with Java hosting apps or tomcat service?

Leave a Reply