• 4
Votes
name
name Punditsdkoslkdosdkoskdo

How do determine JAVA_HOME in Debian/Ubuntu?

On Ubuntu it is possible to have multiple JVMs at the same time. The default one is selected with update-alternatives. But this does not set the JAVA_HOME environment variable, due to a debian policy.

I am writing a launcher script (bash), which starts a java application. This java application needs the JAVA_HOME environment variable. So how to get the path of the JVM which is currently selected by update-alternatives?

Type in terminal,

echo $JAVA_HOME

Display JAVA_HOME variable path.

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 & version

For displaying follow first command.

  • 0
Reply Report

I installed java with

sudo apt-get install openjdk-7-jre-headless

and then to find the location

ls -al /etc/alternatives/java
  • 0
Reply Report

For the JRE, something like this should do the trick:

JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
  • 4
Reply Report