Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
Ubuntu 11.04
open terminal
JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/
export JAVA_HOME
echo $JAVA_HOME 
==>/usr/lib/jvm/java-6-sun-1.6.0.24/

i close the terminal 
open another terminal
echo $JAVA_HOME 
==>

Any idea why JAVA_HOME was not saved ?

share|improve this question

2 Answers 2

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"
      JAVA_HOME=/usr/java/default
  fi
  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=$(<java.home.config)
else
  JAVA_HOME_CANDIDATES=$(find /usr -type d -name '*jdk1.6*')
  echo "Found the following candidates for JAVA_HOME. Pick one: "
  echo "---"
  echo $JAVA_HOME_CANDIDATES
  echo "---"
  read USER_SUBMITTED_JAVA_HOME
  echo "You chose $USER_SUBMITTED_JAVA_HOME ."
  JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
fi
set_java_home
share|improve this answer
    
impressive ...thanks ! –  Cris Jun 24 '11 at 21:16
1  
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." gnu.org/software/bash/manual/bash.html#Bourne-Shell-Builtins –  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

 
discard

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.