Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA_HOME change automatically in Linux

Tags:

java

linux

I set my JAVA_HOME path by 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 echo $JAVA_HOME, the command will not get any result. That is, there is no JAVA_HOME set.

like image 827
Priyanka Shaju Avatar asked May 24 '26 05:05

Priyanka Shaju


1 Answers

export only makes available the variable to the current and child processes, it is cleared, when you terminate your process.

You may put your export command into your ~/.bashrc file to have it always available.

So, open your ~/.bashrc file with a text editor, and put this into the first line:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/jre

save the file, and after a relog, you can always use the veriable in shell scripts.

Other option (actually the recommended one by Ubuntu documentation) is to put this line into /etc/environment, this way the variable will be set for all users.

like image 101
meskobalazs Avatar answered May 26 '26 18:05

meskobalazs