plroqeve
By:
plroqeve

$JAVA_HOME path not sourced correctly in ~/bash_profile at login?

October 11, 2017 77 views
Linux Basics Control Panels CentOS

Hi,

Upon logging into my CentOS 7 VM, my $JAVAHOME is always set to : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x8664/jre, which is incorrect.

My ~/.bash_profile reads:

.bash_profile

Get the aliases and functions

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

User specific environment and startup programs

JAVAHOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el74.x8664/jre
export JAVA
HOME

PYCHARMHOME=/opt/pycharm-community-2017.2.3/
export PYCHARM
HOME

ECLIPSEHOME=/opt/eclipse
export ECLIPSE
HOME

export SPARK_HOME=/opt/spark

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVAHOME/bin:$SPARKHOME/bin:$PYCHARMHOME/bin:$ECLIPSEHOME

export PATH
Sourcing .bashprofile each time I open a new terminal appears to correct the issue, but why is my $JAVAHOME path defaulting to an old version on startup and not being set to the directory specified in .bash_profile?

help me!

1 Answer

Try putting them in the ~/.bashrc file instead of the ~/.bash_profile file.

Basically.. when you start the shell, .bashrc will be sourced at first. I think this SuperUser answer will explain the difference much better than me, as it's a bit of longer answer.

Have another answer? Share your knowledge.