This is the personal blog of Neil Ang. Simple and interesting technology articles written by a developer for developers. Feel free to comment on posts or link to this site. Constructive feedback is always welcomed.

How to install Tomcat on Mac OS X

Posted: 11 January 2007

A while back I wrote a post on the ubuntu forums on how to install Tomcat on ubuntu. It was very popular (if I do say myself) so I thought I would post the instructions on how to setup tomcat on Apple's OS X. These instructions work for 10.4 (Tiger) and 10.5 (Leopard).

Installing Tomcat

  1. Download the latest core binary distributions of tomcat from http://tomcat.apache.org/ (do not download the windows service installer).
  2. Unzip the download and rename the folder from "apache-tomcat-x-x-xx" to something simple like "Tomcat".
  3. Move the folder to the root /Library directory (or somewhere else convenient). Tomcat is installed. That's it!
  4. To start tomcat run startup.sh found in /Library/Tomcat/bin. To stop tomcat run shutdown.sh found in the same bin directory. After starting tomcat navigate to http://localhost:8080 to see if the server is working.

Custom Tomcat Start/Stop Script

To make starting and stopping tomcat easier you can create a custom shell script to turn tomcat on and off through terminal.

Open up your favorite text editor (mine is TextMate) and add the following code:

#!/bin/bash

case $1 in
  start)
    sh /Library/Tomcat/bin/startup.sh
  ;;
  stop)
    sh /Library/Tomcat/bin/shutdown.sh
  ;;
  restart)
    sh /Library/Tomcat/bin/shutdown.sh
    sh /Library/Tomcat/bin/startup.sh
  ;;
  *)
    echo "Usage: start|stop|restart"
  ;;
esac

exit 0

Save the file with the title "tomcat" (in lowercase and no extension). Place the file in a bin directory which is included in your terminal's path e.g. /usr/bin. Now when you want to use tomcat, simply write "tomcat start" and "tomcat stop" in terminal.

Leave a comment if you have any suggestions, troubleshooting or ideas.

Your comments (subscribe)

Gravatar

Michael Potter 1 Sep 07 at 11:08am

Thanks so much for posting these instructions. I'm not an amateur computer user by any means, but I thought I needed to build Tomcat from source in order to get it to work in OS X … Couldn't figure out why it wasn't working, but your method is 100x easier.

Gravatar

Mars Sjoden 1 Sep 07 at 11:09am

Great little tutorial for Tomcat install on Mac OSX.

I just thought I would mention that when I extracted the .zip file of the Core Binary download distribution, the permissions were set incorrectly and thus I recieved this error "/Library/Tomcat/bin/catalina.sh not found"

It was necessary to change the permissions so that all the scripts would be executable:

chmod 755 /Library/Tomcat/*.sh chmod 755 /Library/Tomcat/*.bat

Also, just incase anyone recieves a"JAVA_HOME not defined" error, it is necessary to set your java home like so:

setenv JAVA_HOME /Library/Java/Home

These may be very trivial errors, however, they did have me scratching to figure them out.

Great Blog!

Mars

Gravatar

chris 1 Sep 07 at 11:10am

Thanks for the tutorial, and thanks mars for that permission tip, I was struggling with that for some time.

Chris

Gravatar

Henry 1 Sep 07 at 11:11am

Thx for the guide and thx to mars too for the tip!

Gravatar

Varaprasad 1 Sep 07 at 11:11am

Thanks dude. It was very helpful. Explained in very simple terms.

Thanks again.

Gravatar

SHAZ 1 Sep 07 at 11:12am

YOU ROCK. For some reason I had to restart to get mine working =SSS May just be a me thing ^_^

Gravatar

Scott 11 Sep 07 at 10:24pm

I did the above steps and when I type in tomcat start, I do not see any feedback that anything has started and when I go to the 8080 page, "it could not connect". I am guessing I am missing some step somewhere like setting a variable or something obvious, I am just not seeing it. I do not know much about the command line.

Gravatar

Howard 11 Jan 08 at 1:57pm

Another way to start is to 2x click on the SH and have terminal open it.

Gravatar

Tyler 14 Jan 08 at 5:02pm

I got this error below :

/Library/tomcat/bin/catalina.sh: line 338: 364 Bus error "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" -Dcatalina.base="$CATALINA_BASE" -Dcatalina.home="$CATALINA_HOME" -Djava.io.tmpdir="$CATALINA_TMPDIR" org.apache.catalina.startup.Bootstrap "$@" stop

pls tell me why ? thx a lot

Gravatar

Charlie 16 Jan 08 at 0:24am

I get this when I try setenv ??????

-bash: setenv: command not found

Gravatar

raj 7 May 08 at 11:49am

I also had to change the ports 8080 and 8009 in server.xml

Gravatar

David U 28 May 08 at 9:36pm

Awesome article! It is much more simple than all the other tomcat installation articles out there.

Moving on, I quickly got sick of the default web root of /Library/Tomcat/webapps/ROOT, so I renamed ROOT/ to ROOT_OLD/ and used the following command to move the root to my sites directory:

ln -s /Users/username/Sites/tcroot/ /Library/Tomcat/webapps/ROOT

Works great!

Gravatar

Ben 28 May 08 at 9:42pm

I created the startup script and put it in in my /usr/bin directory, but got this error when I tried to run it:

-bash: /usr/bin/tomcat: Permission denied

I then ran chmod 775 tomcat on the file and now it doesn't give me the error, but it doesn't do anything either. Any ideas?

Gravatar

Neil 28 May 08 at 9:43pm

Have a look at Mars comment above. If that doesn't work, check the tomcat logs to see if anything strange is showing up in there.

Gravatar

Andrew Hedges 13 Jun 08 at 0:40am

Super easy. Thanks!

Gravatar

Mahmoud Abu-Wardeh 16 Sep 08 at 6:23am

Thanks for the tutorial. Great help.

Gravatar

harpreet 19 Sep 08 at 6:51am

great work,, keep up the good work, veru very helpfull thank you

Gravatar

TerTer 30 Oct 08 at 6:21pm

Thank you.. For some reason apache documentation seems to be written for the likes of Richard Stallman, which I find impossible (no 'how tos' or context). Thank you for making/keeping it simple.

Gravatar

Maverick 26 Feb 09 at 2:26pm

$ Applications/Softwares/Tomcat/Tomcat/bin/startup.sh The BASEDIR environment variable is not defined correctly This environment variable is needed to run this program

What is it? Help please

Gravatar

Neil 26 Feb 09 at 2:46pm

@Maverick I haven't come across that problem before. Try setting JAVA_HOME and CATALINA_HOME and see if that fixes it.

export JAVA_HOME=/Library/Java/Home
export CATALINA_HOME=/Library/Tomcat/

Gravatar

Maverick 26 Feb 09 at 3:02pm

Thanks for the quick reply, I figured out. I just changed the mod of the startup.sh and shutdown.sh files but didn't do the same for Catalina.sh.

Thanks.

Gravatar

Ronald 14 Apr 09 at 2:07pm

OSX 10.5's web server conflicts with Tomcat. If you have web sharing enabled on your box you may have to disable it for Tomcat to work. That's what I had to do.

Gravatar

Neil 14 Apr 09 at 2:10pm

@Ronald did you have Tomcat and Apache operating on the same port? By default apache will use 80, and tomcat should use 8080. Both can be run at the same time ;)

Gravatar

Javathreads 9 Jun 09 at 3:49am

Thanks very much, very useful:))) I don't understand why all the tutorial out there for tomcat are for window$. Great job, thanks very much

Post a comment

Comment Guidelines

  • You can subscribe to the comments on this entry via RSS.
  • Have no more than 2 links, otherwise your comment will be flagged as spam.
  • Links are automagically generated.
  • <em>text</em> to make text italic.
  • <strong>text</strong> to make text bold.

JavaScript needs to be enabled to comment.