Set JAVA_HOME / PATH for a single user
Login to your account and open .bash_profile file
$ vi ~/.bash_profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=.set it as follows:
export JAVA_HOME=/opt/java/jdk1.8.0_40
Set PATH as follows:
export PATH=$PATH:/opt/java/jdk1.8.0_40/bin
Save and close the file. type the following command to activate the new path settings immediately:
source ~/.bash_profile
Set JAVA_HOME / PATH for all user
You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
vi /etc/profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=.set it as follows:
export JAVA_HOME=/opt/java/jdk1.8.0_40
Set PATH as follows:
export PATH=$PATH:/opt/java/jdk1.8.0_40/bin
After saving profile file, run the below command to make it work
. /etc/profile