Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm running Tomcat using the tomcat6 package from Ubuntu 9.04, which makes a daemon out of Tomcat using jsvc. I'd like to know the proper way to set Java heap options like -Xmx for Tomcat. I'd like to put the configuration wherever is most stylistically correct, and wherever is least likely to be overwritten by Ubuntu package updates.

The options I see right now:

  • Hard-code them somewhere in /etc/init.d/tomcat6.
  • Hard-code them somewhere in /usr/share/tomcat6/bin/
  • Create a line in /usr/share/tomcat6/bin/ to set CATALINA_OPTS to have the desired flags, and then export CATALINA_OPTS as an environment variable. (This looks like it will get picked up by

The last option sounds like the best one, and it's advocated (without explanation of why) at Increasing Java's heapspace in Tomcat startup script. But I wanted to get a second opinion. Anyone want to confirm that there isn't a better way?

share|improve this question

4 Answers 4

Look for /etc/tomcat6/tomcat6.conf which has the likes of JAVA_OPTS ready and waiting for you to uncomment (but only if you have it at all, I'm using Centos not Ubuntu).

# System-wide configuration file for tomcat6 services
# This will be sourced by tomcat6 and any secondary service
# Values will be overridden by service-specific configuration
# files in /etc/sysconfig
# Use this one to change default values for all services
# Change the service specific ones to affect only one service
# (see, for instance, /etc/sysconfig/tomcat6)
#JAVA_OPTS="-Xminf0.1 -Xmaxf0.3"
share|improve this answer
This seems to be correct for CentOS / yum / RPM version of tomcat. For the Ubuntu / apt-get package the is the right way to go AFAIK – Eran Medan Apr 30 '14 at 19:20
yes, KCD is correct, for centOS tomcat6.conf works well. Checked with the command ps aux | grep tomcat it shows the parameter with the values i set. – Manikandan Arunachalam Nov 14 at 8:17

If you look in your installation's bin directory you will see or .bat scripts. If you look in these you will see that they run a or setenv.bat script respectively, if it exists, to set environment variables. The relevant environment variables are described in the comments at the top of To use them create, for example, a file $CATALINA_HOME/bin/ with contents

export JAVA_OPTS="-server -Xmx512m"

For Windows you will need, in setenv.bat, something like

set JAVA_OPTS=-server -Xmx768m

This is true from tomcat 5.5 through 7. Original answear

share|improve this answer
Works well for systems without the /etc/default/ include, e.g, FreeBSD. – vadipp May 22 '13 at 17:09

At least on Ubuntu 10.04, /etc/init.d/tomcat6 sources /etc/default/tomcat6 if it exists. That's where I put my overrides, and I believe it's generally the "approved" way to make such changes.

share|improve this answer
/etc/default/tomcat6 is the proper place – Amala Jun 30 '11 at 20:05
+1 Configuration should always be done in /etc if possible. – Marcus Downing Jan 23 '13 at 10:50
On CentOS, the location I found was /etc/tomcat6/tomcat6.conf – khylo Feb 19 '13 at 15:45
On CentOS 6.4, /etc/tomcat6/tomcat6.conf is a large file and I didn't want to put my personal customizations in there, so I created $CATALINA_HOME/bin/ and sourced it in /usr/sbin/tomcat6. Hope this helps CentOS users (yes, I know the original question was for Ubuntu). – DuffJ Sep 1 '13 at 15:14
@khylo yep, took me a little while to figure it out. seems in CentOS the /etc/init.d/tomcat6 is calling /usr/sbin/tomcat6 which is NOT calling but simply calls the tomcat bootstrap class directly (as opposed to the Ubuntu /etc/init.d/tomcat6 that is calling – Eran Medan Apr 30 '14 at 19:22

The most elegant way I've found so far is to edit /etc/init.d/tomcat6 and add this at the top of the file:

# local config settings
JAVA_OPTS="-Xms5000m -Xmx13000m

The other options I outlined in my question don't seem to work. After studying the script and experimenting some more, I now doubt that /usr/share/tomcat6/bin/ and /usr/share/tomcat6/bin/ play any role in tomcat startup with the tomcat6 Ubuntu package. Instead; the /etc/init.d/tomcat6 completely replaces any work that might normally be done by

I'm still a little worried about losing these config options in some future package update, but I guess if that happens it'd be pretty easy to restore them.

share|improve this answer
Can this be set (exported) in the .bashrc for whatever user you want tomcat to run as ? [please excuse horrid grammar] That would survive updates to Tomcat package, etc. I'm assuming the "run-as" facility in init will start normal shell for that user and pick up the assignment. See also – David J. Liszewski Jul 8 '10 at 14:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.