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
Simply do (in terminal):
update-alternatives --list java And you'll get an output like this:
$ 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.
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?
0export 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.
1Starting 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.
Installation
I followed the instruction on the official documentation to install Java with .tar.gz
Path setting
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.