Set JAVA_HOME/PATH environment variable on CentOS/RHEL

Scenario: Set JAVA_HOME/PATH environment variable on CentOS/RHEL
System: CentOS/RHEL 6/7

– Set JAVA_HOME / PATH for a single user,example set up on user bachem
1) Check java path
Refer to below output the path is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre

2) Login as bachem then edit .bash_profile
# su - bachem
$ vi /home/bachem/.bash_profile

add below

3) Apply Java environment and path, run below command
$ source /home/bachem/.bash_profile

Output:

– Set JAVA_HOME / PATH for a all user
1) Edit /etc/profile, example using java path above.
# vi /etc/profile
add below

2) Apply Java environment and path, run below command
$ source /etc/profile

Output:

References:
https://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/
http://sharadchhetri.com/2013/06/03/how-to-set-java-environment-variables-in-linux-or-centos/


Related posts:

Leave a Reply

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