3

I installed java-8 using a PPA. After that I gave a command:

export JAVA_HOME=/usr/lib/jvm/java-8-oracle

I had heard somewhere that this command does temporary changes. But after many logouts and logins, these commands below still works (I think due to that export ... command):

java -version
javac -version

But when I give the command:

export -p

It shows a list of environment variables, but in that list, does not show variable JAVA_HOME. Moreover, I wonder how the commands java and javac still works!

Can someone tell me in which file export command make changes? Are they temporary or permanent? And what else happens above? Please elaborate!

muru
  • 197,895
  • 55
  • 485
  • 740
Ankur Shah
  • 217
  • 1
  • 2
  • 9

1 Answers1

8

export is a shell command. It affects the current running instance of the shell. It does not make changes in any file. The changes are temporary, only in effect until the shell exits. Once you set a new variable in the shell, to make it available to other programs started from it, you export it. See:

java and javac might work because you installed Java using a PPA, and the installation automatically added these commands to the PATH (What is the PATH environment variable and how do I add to it?). Specifically, just checking the version shouldn't need the JAVA_HOME variable. Whether you set it or not makes no difference just for that. And apparently JAVA_HOME is used by other applications, not the Java compiler or the JVM.

muru
  • 197,895
  • 55
  • 485
  • 740
  • I checked the file /etc/environment, but there is nothing like /usr/lib/jvm/java-8-oracle... assigned in the PATH variable. Then what else might be happening? – Ankur Shah Mar 20 '16 at 09:33
  • @AnkurShah run type -a java javac. Are those directories in your PATH? – muru Mar 20 '16 at 09:34
  • I typed the command and I get this: java is /usr/bin/java , javac is /usr/bin/javac. And I also saw /usr/bin in PATH variable. I think I get it now! Is it? – Ankur Shah Mar 20 '16 at 09:38
  • @AnkurShah that's it. The PPA you used installed the commands to /usr/bin, which is already in PATH, so no changes to PATH were needed. JAVA_HOME is for other software, so just the java and javac commands will work without it. – muru Mar 20 '16 at 09:43