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 ?
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