I needed to update my openJDK to 8 version... And I downloaded the 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 check the Java version

java -version

I 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 was it saved? I need to know because I should set this path into AndroidStudio.

4 Answers 4


Simply do (in terminal):

update-alternatives --list java

And you'll get an output like this:

 $ update-alternatives --list java

The last line is the place your java is in.


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?

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

$ update-alternatives --list 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.

  • Be aware of the possibility that people might have two JDK's installed. To always use the first one as your JAVA_HOME you can use head: JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac 2>&1 | head -n 1)))
    – luukvhoudt
    Mar 20, 2021 at 11:29

Starting from January 2019, the licensing model for Oracle Java has changed. PPAs such as 'ppa:webupd8team/java' used in many Java installation tutorials now become unavailable.

Here I would like to share how I installed Java 8 on Ubuntu 16.04, and set the Java path in terminal.


Reference: https://java.com/en/download/help/linux_x64_install.xml

I followed the instruction on the official documentation to install Java with .tar.gz

Path setting

Reference: https://java.com/en/download/help/path.xml

The instruction is also from the official documentations. The steps to set up Java path are much simpler here.

After performing all the steps, restart the terminal and run 'java -version' to verify installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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