2

Executing below two commands on mac Terminal which set environment variable, which is vanished on close of Terminal, any help would be appreciated

Step 1:- echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.profile 
Step 2:- . ~/.profile

Initial Terminal output

karthiks-MacBook-Air:~ karthicklove$ echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.profile

karthiks-MacBook-Air:~ karthicklove$ . ~/.profile

karthiks-MacBook-Air:~ karthicklove$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

Terminal output after closing and reopen again

karthiks-MacBook-Air:~ karthicklove$ echo $JAVA_HOME

karthiks-MacBook-Air:~ karthicklove$ 
  • try adding to .bash_profile – Suraj Rao Mar 28 '17 at 04:47
  • 2
    Possible duplicate of [Setting JAVA\_HOME environment variable on MAC OSX 10.9](http://stackoverflow.com/questions/22842743/setting-java-home-environment-variable-on-mac-osx-10-9) – Suraj Rao Mar 28 '17 at 04:50

1 Answers1

3

Create a file called .bash_profile in your home directory and add the JAVA_HOME variable in it.

export JAVA_HOME=`/usr/libexec/java_home`

This file is loaded every time you open terminal or you open a new terminal tab. Please note that the file needs to be hidden.

djames
  • 366
  • 5
  • 17
  • Thanks issue is resolved modifying to .base_profile as below Step 1:- echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.bash_profile Step 2:- . ~/.bash_profile – Vinoth Kumar Subramanian Mar 28 '17 at 05:07
  • @VinothKumarSubramanian if you found the answer to be useful, please accept the answer with the tick. – djames Mar 28 '17 at 05:58