JAVA_HOME automatically changes on Linux
I set my JAVA_HOME path using the command:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/jre/bin/java
Then when I use this: echo $JAVA_HOME
I get:
/usr/lib/jvm/java-7-openjdk-i386/jre/bin/java
But when I close the terminal and then open it and check it echo $JAVA_HOME
, the command doesn't get any output. That is, there is no JAVA_HOME set.
source to share
export
only gives access to the variable to the current and child processes, it is cleared when you terminate your process.
You can put your export command in your ~/.bashrc
file to keep it always available.
So, open your ~/.bashrc
file with a text editor and put it on the first line:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/jre
save the file and after reinstalling you can always use verification in shell scripts.
Another option (actually recommended by the Ubuntu documentation ) is to put this line in /etc/environment
, so the variable will be set for all users.
source to share
to know using java version, java -showversion
To check if the java path is set or not used, echo $JAVA_HOME
Use the following command to set Java path
sudo gedit /etc/environment
In file JAVA_HOME
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/
do not forget to specify the full path to the folder containing bin/java
.
Restart the system to activate the changes.
source to share