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:


Add this line to the /etc/environment file:
Add JAVA_HOME/bin to the PATH variable.

Change the file as:


(define JAVA_HOME always before PATH)

Now check PATH and JAVA_HOME using:

echo $PATH

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 *