Monday, October 20, 2008

How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

Set JAVA_HOME / PATH for single user


Login to your account and open .bash_profile file

$ vi ~/.bash_profile

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

Set PATH as follows:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file. Just logout and login back to see new changes:

$ echo $JAVA_HOME

$ echo $PATH


Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:

$ which java


Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.


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

Next setup PATH / JAVA_PATH variables as follows:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin



Save and close the file.



Link http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

No comments: