How to set up PATH and JAVA_HOME variable in Ubuntu

Open “Application->Terminal” and type:

sudo nautilus

This opens the file browser as root.

Now go to “/etc” and open “environment” file.
Here is what you might see in environment file:

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
/sbin:/bin:/usr/games:”

Add this line to the /etc/environment file:
JAVA_HOME=”/usr/lib/jvm/jdk1.6.0_23″
Add JAVA_HOME/bin to the PATH variable.

Change the file as:

JAVA_HOME=”/opt/java/jdk/jdk1.6.0_25″
PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
/sbin:/bin:/usr/games:JAVA_HOME/bin”

(define JAVA_HOME always before PATH)

Now check PATH and JAVA_HOME using:

echo $PATH
echo $JAVA_HOME

Now to check the version:

java -version

If you dont find java installed, create these symbolic links:

sudo ln -s /opt/java/jdk/jdk1.6.0_25/bin/java /usr/bin/java
sudo ln -s /opt/java/jdk/jdk1.6.0_25/bin/javac /usr/bin/javac

Now check the following:
java -version
you will get something like:
java version “1.6.0_25”
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)

showing java installed.

Leave a Reply

Your email address will not be published. Required fields are marked *