1

I downloaded and installed the JDK+Netbeans bundle from the Oracle website, but when I type java -version at the terminal, I get this output:

$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
Try: sudo apt-get install <selected package>  

Firstly, what does this mean? Are there multiple versions of java installed on my system?
Secondly, there is a JDK folder that got created after I installed Netbeans+JDK. These are the contents of the folder:

$ pwd
/usr/local/jdk1.8.0_65
$ ls
bin        javafx-src.zip  man          THIRDPARTYLICENSEREADME-JAVAFX.txt
COPYRIGHT  jre             README.html  THIRDPARTYLICENSEREADME.txt
db         lib             release
include    LICENSE         src.zip

Thirdly, Android Studio isn't able to find JDK_HOME even though I gave export JDK_HOME=/usr/local/jdk1.8.0_65 in bashrc. What could be done?

I'm considering deleting the jdk1.8.0_65 folder and using sudo apt-get install default-jre and sudo apt-get install default-jdk, but am apprehensive if deleting the jdk folder would mess up something, or whether the apt-get commands would download the latest version of Java.

UPDATE:
Tried adding the bin folder to PATH, but although the java version is being shown properly, android studio isn't able to find the JDK.

$ echo $PATH
/usr/local/jdk1.8.0_65/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
$ android
[sudo] password for nav: 
ERROR: Cannot start Android Studio
No JDK found. Please validate either STUDIO_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation.
$ echo $JAVA_HOME
/usr/local/jdk1.8.0_65/bin
$ echo $JDK_HOME
/usr/local/jdk1.8.0_65
$  
Nav
  • 1,059

2 Answers2

1

What you are missing is adding jdk1.8.0_65/bin folder to your PATH environmental variable.

Firstly, what does this mean? Are there multiple versions of java installed on my system?

No, but the one you installed in /usr/local/jdk1.8.0_65 isn't located by other programs like netbeans or android that depend on Java. To verify it for yourself, just open up your terminal and add the folder containing java executable to your path variable like this:

export PATH="/usr/local/jdk1.8.0_65/bin:$PATH"

To test whether this was successful, go to any directory and fire this command:

java -version

Once that is a success, go to netbeans folder and execute it:

./netbeans

If all other settings are good, it should run and so should android! To make the changes permanent, add the path modifier to your ~/.profile file (otherwise, you will have to issue the export command each time you open the terminal to work with java).

Prahlad Yeri
  • 1,657
  • Thanks. Although this did solve the java -version display problem, Android studio still seems unable to find the JDK. I've updated my question with the output. (btw, Netbeans was working fine even before I exported the JDK bin folder in PATH) – Nav Dec 18 '15 at 17:19
  • @Nav AS is based on Intellij IDEA, so you can use the same trick mentioned here to tell it the JDK path - In IntelliJ IDEA (and likely the same in Android Studio) go to File > Project Structure > [Platform Settings] > SDKs. – Prahlad Yeri Dec 18 '15 at 20:28
  • Well, Android studio isn't even starting, so going to the menu is not the solution :) – Nav Dec 19 '15 at 14:26
  • It turns out that AS checks both JAVA_HOME and JDK_HOME environment variables. I'm sure one of them is incorrect in your case. To verify, try these two commands in succession: echo $JAVA_HOME and echo $JDK_HOME and make sure of two things: 1) At least one of them is set correctly. 2) The other is either blank or correctly set, but not pointing to an invalid location. – Prahlad Yeri Dec 19 '15 at 15:34
0

Firstly, what does this mean? Are there multiple versions of java installed on my system?

No, these are package options to install to get java. You have currently chosen to install outside the package system.

It is simplest to use the package-supported versions of java if you can. This way you can simply update your packages, rather than having to install another JDK and change all of your pointers to the new version.

Thirdly, Android Studio isn't able to find JDK_HOME even though I gave export JDK_HOME=/usr/local/jdk1.8.0_65 in bashrc. What could be done?

At this time, you need Java 7 to develop with Android Studio. http://developer.android.com/sdk/installing/index.html?pkg=studio https://stackoverflow.com/questions/23318109/is-it-possible-to-use-java-8-for-android-development

mattm
  • 190