How to find my current JAVA_HOME in ubuntu?
Solution 1:
To display JAVA_HOME
variable path, type in terminal:
echo $JAVA_HOME
If nothing appears then set it with this:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
This will differ according to your JDK type and version.
For displaying it again, follow the first command.
Follow JREs from different vendors on the same system, for using different JDK's or switch between JDK's.
Solution 2:
If you have JDK 1.6 (corresponding to Java 6) or a newer version installed, you should have a program named jrunscript
in your PATH
. You can use this to find the corresponding JAVA_HOME
. Example:
$ jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'
/opt/local/jdk1.7.0_76/jre
You could set the environment variable like this:
$ export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"
Note that the JRE doesn't include jrunscript
, so this will only work if you install the JDK, not just the JRE.
Solution 3:
Another portable options is to extract the absolute path of the JRE from java
:
export JAVA_HOME=`type -p java|xargs readlink -f|xargs dirname|xargs dirname`
The absolute java
path is passed to dirname
twice to remove /bin/java
from the end. Complete extraction of the directory goes as follows:
$ type -p java
/usr/bin/java
$ readlink -f /usr/bin/java
/usr/lib/jvm/java-8-oracle/bin/java
$ dirname /usr/lib/jvm/java-8-oracle/bin/java
/usr/lib/jvm/java-8-oracle/bin/
$ dirname /usr/lib/jvm/java-8-oracle/bin/
/usr/lib/jvm/java-8-oracle/