How to set JAVA_HOME to point to a JDK installation?

I installed sun-java6-jdk.

I need to find its home directory. JAVA_HOME must point to a JDK installation, not JRE.


Solution 1:

You should be able to use the whereis command to find where your JDK is installed.

whereis java

On my Ubuntu 12.04 install, OpenJDK has files located in /usr/bin/java, /usr/bin/X11/java, /usr/share/java, /usr/share/man/man1/java.1.gz. I'm guessing the Oracle version is located in the same directories.

Solution 2:

If you need to add JAVA_HOME variable, you can do so by adding it to the .bashrc file in your home directory

Open .bashrc file using an editor. If you use nano then

nano ~/.bashrc

and add the following 2 lines in your .bashrc file.

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_04/
export JAVA_HOME

There may be other ways to install, but this is what I have followed always.

Solution 3:

This is how I configured in my Linux system:

I downloaded JDK1.8.0_77 and by default the downloaded file is in the location (Downloads directory) i.e /home/user/Downloads, unpacked the downloaded JDK to /home/user/Downloads/jdk1.8.0_77 and then

  1. Open Terminal and type,

    editor .bashrc
    

    write these 2 lines inside,

    export JAVA_HOME=/home/user/Downloads/jdk1.8.0_77
    

    (enter the path of your downloaded JDK)

    export PATH=$JAVA_HOME/bin:$PATH
    

    save the file

  2. source ~/.bashrc

  3. echo $JAVA_HOME

That's it :)