Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to configure Tomcat to know where JAVA_HOME is. I am used to Windows :) ...which file should I edit to add the Java info, and where is it located?

share|improve this question
No need to post a greeting or sign your posts. Just post the question itself. We all know who you are, and your acceptance of our answers is thanks enough. :) – EEAA Apr 4 '11 at 20:44
That depends. Are you talking about when you develop or for a production system? – Bittrance Apr 4 '11 at 20:44
@ErikA "we all know who you are" ---- oyoyoy, have I asked that many dumb questions already? :) – Genadinik Apr 4 '11 at 20:53
@Bittrance this is for a development environment – Genadinik Apr 4 '11 at 20:53
hah, no...your signature/profile block gets posted automatically as you no doubt already know. – EEAA Apr 4 '11 at 20:54
up vote 6 down vote accepted

For development work:

If your shell is bash (echo $SHELL -> /bin/bash) you may want to add a JAVA_HOME entry in /home/<user>/.bashrc. However, note that if you only work with one Java version, you should install the package and no explicit JAVA_HOME setting should be necessary for most scenarios.

Also, it is sometimes convenient to do something like this:

$ JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun mvn package

Which means to set JAVA_HOME for this command only.

share|improve this answer
Also you can run export JAVA_HOME=/usr/lib/jvm/ to just set JAVA_HOME for one shell session. – Jason Axelson Apr 5 '11 at 0:14

Using Oracle JDK, here is how I set mine. Don't forget the "-p" in your export command.

# Set the JAVA_HOME variable
function set_java_home {
  echo "Searching for java ..."
  if [ -z $JAVA_HOME ]; then
      echo "Using default value for JAVA_HOME: /usr/java/default"
  export -p JAVA_HOME
  echo $JAVA_HOME > java.home.config
  sudo rm /etc/alternatives/java
  sudo ln -s $JAVA_HOME/bin/java /etc/alternatives/java
  echo "JAVA_HOME variable set to $JAVA_HOME and /etc/alternatives set."
if [ -f java.home.config ]; then
  JAVA_HOME_CANDIDATES=$(find /usr -type d -name '*jdk1.6*')
  echo "Found the following candidates for JAVA_HOME. Pick one: "
  echo "---"
  echo "---"
  echo "You chose $USER_SUBMITTED_JAVA_HOME ."
share|improve this answer

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.