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
- Download the latest core binary distributions of tomcat from http://tomcat.apache.org/ (do not download the windows service installer).
- Unzip the download and rename the folder from "apache-tomcat-x-x-xx" to something simple like "Tomcat".
- Move the folder to the root /Library directory (or somewhere else convenient). Tomcat is installed. That's it!
- 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.
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.
Your comments (subscribe)
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.
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
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
Henry 1 Sep 07 at 11:11am
Thx for the guide and thx to mars too for the tip!
Varaprasad 1 Sep 07 at 11:11am
Thanks dude. It was very helpful. Explained in very simple terms.
Thanks again.
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 ^_^
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.
Howard 11 Jan 08 at 1:57pm
Another way to start is to 2x click on the SH and have terminal open it.
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
Charlie 16 Jan 08 at 0:24am
I get this when I try setenv ??????
-bash: setenv: command not found
raj 7 May 08 at 11:49am
I also had to change the ports 8080 and 8009 in server.xml
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!
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?
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.
Andrew Hedges 13 Jun 08 at 0:40am
Super easy. Thanks!
Mahmoud Abu-Wardeh 16 Sep 08 at 6:23am
Thanks for the tutorial. Great help.
harpreet 19 Sep 08 at 6:51am
great work,, keep up the good work, veru very helpfull thank you
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.
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
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/
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.
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.
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 ;)
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