Skip to content

Instantly share code, notes, and snippets.

@dhavalv
Last active December 22, 2016 08:15
Show Gist options
  • Save dhavalv/44ad5ae57800bbe9168bc4f64c42202f to your computer and use it in GitHub Desktop.
Save dhavalv/44ad5ae57800bbe9168bc4f64c42202f to your computer and use it in GitHub Desktop.
Java installation and find path

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.

Dig again:

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.

Please use this command:

readlink -f $(which java)

It works for me with Ubuntu gnome.

On my computer the result is:

/usr/lib/jvm/java-7-oracle/jre/bin/java

Export alternatives path and set java sdk path to your alternatives

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
export ANDROID_HOME=/opt/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools

sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

Reload environment

source /etc/environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment