How to set java path in Linux?

Ans : Check where java is installed by using below command

#update-alternatives --config java
This command will show installed java packages in your machine.
Example output :
# update-alternatives --config java

There are 2 programs which provide ‘java’.

Selection ———————————————–

1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java *+

2
From above you can see java version and it’s location.

Setting java path(In Temporary way)

#JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk

#export $JAVA_HOME

Setting java path (In Permanent way)
Edit ~/.bashrc and place below two lines in that file and save the file.

Vi ~/.bashrc
JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk export $JAVA_HOME

Now save the file and exit, then logout and login to make those changes to reflect.

Command

/usr/lib/jvm/jre-1.6.0-openjdk/bin/java