How to determine JAVA_HOME on Debian/Ubuntu?
Solution 1:
For the JRE, something like this should do the trick:
JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
Solution 2:
danadam's solution can easily be adopted to retrieve the JDK (i.e. not JRE) path as required:
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
- Looks for javac Java compiler (instead of java) included in JDK (but not JRE).
- Has no trailing / (stripped off by sed s:/bin... instead of s:bin...)
Solution 3:
export JAVA_HOME=$(dirname $(dirname $(readlink -f /usr/bin/java)))
In .bashrc
was handy for me.
Solution 4:
So, you're saying that this command does nothing for you?
sudo update-alternatives --config java
Solution 5:
I installed java with
sudo apt-get install openjdk-7-jre-headless
and then to find the location
ls -al /etc/alternatives/java