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

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
Ubuntu 11.04
open terminal
export JAVA_HOME
echo $JAVA_HOME 

i close the terminal 
open another terminal
echo $JAVA_HOME 

Any idea why JAVA_HOME was not saved ?

share|improve this question
up vote 1 down vote accepted

Your missing the "-p" for "permanent".

It has some bugs, but here is what I use.

# 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
impressive ...thanks ! – Cris Jun 24 '11 at 21:16
Are you referring to "export -p" ? I don't believe that is for permanent. From the man: "if the -p option is given, a list of exported names is displayed. The -p option displays output in a form that may be reused as input." – micah Jun 24 '11 at 21:21

The environment variable is only set for that session and its children. When you close that terminal process, those environment variables are gone. Typically I would set them in ~/.profile, but that may not be the preferred method.

The Ubuntu documentation for this is here

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.