"java -version" showing a different output. How to find the installed folder and configure JAVA_HOME and JDK_HOME?

7,895

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).

Share:
7,895

Related videos on Youtube

Nav
Author by

Nav

Updated on September 18, 2022

Comments

  • Nav
    Nav over 1 year

    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
    Nav over 8 years
    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)
  • Prahlad Yeri
    Prahlad Yeri over 8 years
    @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.
  • Nav
    Nav over 8 years
    Well, Android studio isn't even starting, so going to the menu is not the solution :)
  • Prahlad Yeri
    Prahlad Yeri over 8 years
    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.