Hi,
Upon logging into my CentOS 7 VM, my $JAVA_HOME is always set to : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre, which is incorrect.
My ~/.bash_profile reads:
if [ -f ~/.bashrc ]; then . ~/.bashrc fi
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre export JAVA_HOME
PYCHARM_HOME=/opt/pycharm-community-2017.2.3/ export PYCHARM_HOME
ECLIPSE_HOME=/opt/eclipse export ECLIPSE_HOME
export SPARK_HOME=/opt/spark
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin:$SPARK_HOME/bin:$PYCHARM_HOME/bin:$ECLIPSE_HOME
export PATH Sourcing .bash_profile each time I open a new terminal appears to correct the issue, but why is my $JAVA_HOME path defaulting to an old version on startup and not being set to the directory specified in .bash_profile?
help me!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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.
Override JAVA_HOME in ~/.bash_profile
To ensure your JAVA_HOME is set correctly, you can add the following to your ~/.bash_profile:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre
export PATH=$PATH:$JAVA_HOME/bin:$SPARK_HOME/bin:$PYCHARM_HOME/bin:$ECLIPSE_HOME/bin
Adding export ensures that the variable is available in all child processes, including any scripts or applications that rely on it.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.