Ubuntu – $JAVA_HOME resets after every terminal login

bashenvironment-variablesjavaopenjdk

I just installed openjdk-8-jdk. I already had openjdk-7-jdk installed. When I ran echo $JAVA_HOME, it printed /usr/lib/jvm/java-7-openjdk-amd64.

So I tried changing the $JAVA_HOME variable but it resets to above path every time I re-open the terminal.
I have tried setting it in /etc/enviroment /etc/profile /etc/bash.bashrc ~/.bashrc but to no avail.

How can I change it? Also, where the $JAVA_HOME is currently set?

Best Answer

Login to your account and open .bash_profile file

$ vi ~/.bash_profile

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java-bin-directory>/java
If you want changes effected without logout, enter command below:

$ source ~/.bash_profile
Related Question