14

I needed to update my openJDK to 8 version... And i was download new one this way

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update 
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
sudo update-alternatives --config javac

When i chech java version

java -version

and get

openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

But where it was save? i need to know because i should set this path into AndroidStudio

18

Simply do (in terminal):

update-alternatives --list java

And you'll get an output like this:

michael@NEXUS-TWO:/usr/lib/x86_64-linux-gnu/bamf$ update-alternatives --list java
/usr/bin/gij-5
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

The last line is the place your java is in.

5

You need to dig into symbolic links. Below is steps to get Java directory

Step 1:

$ whereis java
java: /usr/bin/java /etc/java /usr/share/java

That tells the command java resides in /usr/bin/java.

Step 2:

$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2009-01-15 18:34 /usr/bin/java -> /etc/alternatives/java

So, now we know that /usr/bin/java is actually a symbolic link to /etc/alternatives/java.

Dig deeper using the same method above:

Step 3:

$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 31 2009-01-15 18:34 /etc/alternatives/java -> /usr/local/jre1.6.0_07/bin/java

So, thats the actual location of java: /usr/local/jre.....

You could still dig deeper to find other symbolic links.


Reference : where is java's home dir?

0
export JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac)))

To make this seemingly over done setting clearer, on my Ubuntu linux machine with open JDK 8 installed:

$ update-alternatives --list java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

$ update-alternatives --list javac
/usr/lib/jvm/java-8-openjdk-amd64/bin/javac

but what we need is the path to the directory containing bin of the JDK. So ask for the location of javac and then use dirname twice.

See man update-alternatives for more.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.