0

I am using CentOS. I installed Java8 from the rpm.

Following the tutorial I did this:

export JAVA_HOME=jdk-install-dir

export PATH=$JAVA_HOME/bin:$PATH

However, when I disconnect from SSH it has gone. How can I save the above into the .bash_profile? I believe this is the best way to resolve this problem.

Following this tutorial:

https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/

Thanks!

k1308517
  • 213
  • 3
  • 12

1 Answers1

0

If you want to set an environment variable permanently, you can write the export command line to /etc/profile.d/ (for system wide change) or ~/.bash_profile (for local user).

NOTE: bashrc will be executed whenever a new terminal is opened (AFTER there is a logged in user).

bash_profile will be executed whenever a user is logging in (no matter is it's via ssh or actually sitting in front of the computer)

You can always export the envvars in one file and by sourcing this file in the other file you will have those envvars in both login/non-login shells:

#If you exported the envvars in bash_profile
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

Hope it helps you

I-V
  • 725
  • 4
  • 10
  • If I open .bash_profile in nano, then add this will it work in CentOS? It is not working for me :-(. I doubt I can have two PATH for example? http://pastebin.com/z85KBMKm – k1308517 May 17 '16 at 09:12
  • Did you login after you had changed the file? It should be executed whenever a user login. Anyhow, did you source bash_profile in bashrc? It should solve this problem of "multiple" PATH. If it doesn't, let me know and I'll think of something else :) – I-V May 17 '16 at 10:19
  • Okay I solved it. I used nano and the code from pastebin. Problem was I had to disconnect from SSH, and then reconnect for changes to take affect. JAVA_HOME works fine, appears PATH does too. – k1308517 May 17 '16 at 11:24