Reputation: 349
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$
Upvotes: 2
Views: 3265
Reputation: 366
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.
Upvotes: 3