-1

I am using CentOS 6.5 version. I got sudo permissions and installed java, and set up JAVA_HOME this way .

$ cat /root/.bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64

PATH=$PATH:$JAVA_HOME/bin

export PATH

And now when i did

$ echo $JAVA_HOME
/usr/lib/jvm/jre-1.7.0-openjdk.x86_64

But once i logout and do

$ echo $JAVA_HOME
/usr/local/jdk

Could you please tell me how do i set java_home for all users ??

jww
  • 97,681
  • 90
  • 411
  • 885
Pawan
  • 31,545
  • 102
  • 256
  • 434
  • Possible duplicate of [How to set JAVA\_HOME in Linux for all users](https://stackoverflow.com/q/24641536/608639) – jww Jun 08 '19 at 10:25

2 Answers2

0
vi /etc/profile
export JRE_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export PATH=$PATH:$JRE_HOME/bin

export JAVA_HOME=/your-path-to-java
export JAVA_PATH=$JAVA_HOME

export PATH=$PATH:$JAVA_HOME/bin
Ghayel
  • 1,113
  • 2
  • 10
  • 19
  • Thank you but its not working still the path is being shown as /usr/local/jdk – Pawan Nov 07 '15 at 19:27
  • Yes because the above code sets your JRE path not Java Path. set export JAVA_HOME=/usr.local/jdk and then export PATH=$PATH:$JAVA_HOME/bin. This will set your path accurately. OR change JRE_HOME to JAVA_PATH and all will be set – Ghayel Nov 07 '15 at 19:39
  • One more thing please also activate path settings by using this command. source /etc/profile OR ./etc/profile so path take effect immediately – Ghayel Nov 07 '15 at 19:45
  • I did exactly what you mentioned changed JRE_HOME to JAVA_PATH , but still the same issue exits – Pawan Nov 07 '15 at 19:48
  • Sorry change JRE_HOME to JAVA_HOME and ran comman source /etc/profile – Ghayel Nov 07 '15 at 19:50
  • if i do so how jre_home will be set ?? if u don't mind can u please provide met the updated script ?? – Pawan Nov 07 '15 at 19:51
  • export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64 export JAVA_PATH=$JAVA_HOME export PATH=$PATH:$JAVA_HOME/bin then source /etc/profile – Ghayel Nov 07 '15 at 19:53
  • I need to run tomcat also that JRE_HOME also , so do i need to do the same for setting up JRE_HOME also ?? – Pawan Nov 07 '15 at 19:56
  • 1
    Look dear you have to set JRE_HOME and JAVA_HOME both as I said in my answer. Please follow it and set both. which version of tomcat you are using as you have to set its path as well. – Ghayel Nov 07 '15 at 20:07
  • I shall be more than happy to fix your this problem as well as Tomcat if any. I believe you also need mod_jk connector to serve tomcat pages without port. Let me know if you have any problem with mod_jk or Tomcat – Ghayel Nov 07 '15 at 20:26
  • I believe you also need mod_jk connector to serve tomcat pages without port. Let me know if you have any problem with mod_jk or Tomcat – Ghayel Nov 07 '15 at 20:31
  • Please write here the output of # echo $JAVA_HOME and # echo $PATH? – Ghayel Nov 08 '15 at 11:03
  • Please response to provided answers as this helps to the visitors to get understood which answer fixed your problem. Please mark the correct answer – Ghayel Nov 18 '15 at 18:51
0

System settings for java, CentOS ,,, for all users :

# /usr/sbin/alternatives --config java

Knud Larsen
  • 5,753
  • 2
  • 14
  • 19