Setting Up Tomcat 5 on Ubuntu 6.06

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…

JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/

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!

37 Responses to “Setting Up Tomcat 5 on Ubuntu 6.06

  • 1
    Mark
    July 17th, 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:
    sun-java5-bin
    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
    Chris
    July 17th, 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
    Manolo Canga
    July 20th, 2006 19:31

    Thank you, It’s is very good.
    A spanish translate -> http://bailandodesvan.sytes.net/blog/

    Thank you again.

  • 4
    Chris
    July 21st, 2006 00:03

    @Manola

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

  • 5
    Manolo Canga
    July 22nd, 2006 22:42

    Thanks!.

  • 6
    Uche
    August 9th, 2006 16:44

    Hi,
    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

  • 7
    Tim
    August 18th, 2006 00:21

    Great directions - installed without a hitch. Many thanks!

  • 8
    shashank bala
    August 23rd, 2006 00:25

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

  • 9
    Patrick
    September 6th, 2006 23:57

    Hi there,

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

  • 10
    shrikant
    September 8th, 2006 00:23

    plz give me suggetion about admin setup in tomcat

  • 11
    Jostein
    September 9th, 2006 20:34

    very good! thanks

  • 12
    Casey
    September 25th, 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 http://archive.ubuntu.com/ubuntu dapper multiverse
    deb-src http://archive.ubuntu.com/ubuntu dapper multiverse

    2. Run “sudo apt-get update”

  • 13
    luKas' bloggie [at] vdchuyen.com
    September 25th, 2006 19:50

    Tomcat5 on Ubuntu…

    I’ve found a very usefull articleNote for back-up in case the host would be died …..So, for the basic install use the following com ……

  • 14
    luKas
    September 25th, 2006 19:54

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

  • 15
    Piet
    September 29th, 2006 13:41

    Hi,

    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!

  • 16
    Chris
    September 29th, 2006 16:44

    @Piet

    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.

    Chris

  • 17
    » Re: Tomcat would start - ubuntu.sitebolt.net
    October 3rd, 2006 19:20

    […] i followed the instructions on this page: http://blixtra.org/blog/2006/07/14/setting-up-tomcat-5-on-ubuntu-606/ […]

  • 18
    the rasx() context » Blog Archive » Installing Tomcat
    October 4th, 2006 20:25

    […] http://blixtra.org/blog/2006/07/14/setting-up-tomcat-5-on-ubuntu-606/ […]

  • 19
    Andi
    October 15th, 2006 23:06

    Hi,

    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?

    Andi

  • 20
    PedroB
    October 18th, 2006 21:42

    Congratulations!!!

    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

  • 21
    JamesB
    October 31st, 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 java.util.zip.ZipException: 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.

  • 22
    Olly
    November 8th, 2006 12:56

    Great guide,

    Many thanks

  • 23
    Ubis
    November 11th, 2006 11:47

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

  • 24
    Matthew
    November 20th, 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!

  • 25
    Lam Dros
    November 27th, 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.
    Thanks
    Lam

  • 26
    JanErik
    December 19th, 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.

  • 27
    Mark
    January 4th, 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?

  • 28
    danfolkes
    January 18th, 2007 05:54

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

  • 29
    Mircea
    February 4th, 2007 23:33

    “Hi,

    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.

  • 30
    Mr.ZooM
    February 13th, 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

  • 31
    YMind » Installazione e setup di Tomcat 5 su Ubuntu 6.06 Dapper
    February 13th, 2007 23:48

    […] NOTA: L’articolo seguente è un adattamento del lavoro di Chris Wilson su the blixtra blog. […]

  • 32
    Pasquale
    February 13th, 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 :)
    Pasquale

  • 33
    tuniki
    February 16th, 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

  • 34
    Tim
    February 27th, 2007 22:52

    I just created a german translation, see http://www.thesuntoucher.de/blog/?permalink=2345

  • 35
    Steven G. Harms
    August 20th, 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 ;)

    Steven

  • 36
    Joe Sweeney
    August 29th, 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.

  • 37
    Daniel Orlowski
    October 9th, 2007 11:11

    Works great, thanks!

Leave a Reply