Setting Up JAVA_HOME on Linux

To set the environment variables:

echo 'export JAVA_HOME=/usr/java/jdk1.6.0_21' > /etc/profile.d/

echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile.d/

You have to source the file you just created by typing:

source /etc/profile.d/

Test if Java environment is successfully installed by typing in this in the shell:

$ java -version
java version “1.6.0_03″
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)

You can also use which java to test:

$ which java