$JAVA_HOME resets after every terminal login
Solution 1
I figured it out. It was ridiculous mistake by me.
As I set JAVA_HOME
in so many files, in all the mess I set it to /usr/lib/jvm/java-7-openjdk-amd64
in ~/.bashrc
. So every time I opened the terminal it changed to this no matter what was in all the other files, as ~/.bashrc
runs every time teminal is opened.
Solution 2
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
Solution 3
If you do the changes in /etc/environment then changes will be for current session only. /etc/profile is right place to update paths permanently.You need to make changes in profile under /etc
follow below steps. this should solve your issue
sudo vim /etc/profile
add below 2 lines :
export JAVA_HOME="Your path to jdk folder"
export PATH=$JAVA_HOME/bin:$PATH
to apply changes immediately run below commmand:
source /etc/profile
in the next system reboot changes will be picked automatically.
Solution 4
You should not set this yourself, if it can be helped. To change which Java version to use, see this guide.
Snippet:
If your system has more than one version of Java, configure which one your system uses by entering the following command in a terminal window
sudo update-alternatives --config java
This will present you with a selection that looks similar to the following (the details may differ for you):
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode
Press enter to keep the current choice[*], or type selection number: 1
Related videos on Youtube
suheb
Updated on September 18, 2022Comments
-
suheb over 1 year
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?
-
Ken Sharp over 8 yearsIs there anything in
~/.profile
that shouldn't be there? Just a stab in the dark...
-
-
suheb over 8 yearsDoes
sudo update-alternatives --config java
sets theJAVA_HOME
variable too? -
Anders Olsson over 8 yearsSorry, if it was specifically only about $JAVA_HOME your question was about, my answer was not well researched. On my system (14.04.03) $JAVA_HOME is not set at all.