2

I have just installed gradle from the terminal

sudo apt-get install gradle

After finishing am trying to run the command

gradle -v

I get the following error

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-7-oracle/jre/bin/java

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

When I run echo $JAVA_HOME I get

/usr/lib/jvm/java-7-oracle/jre/bin/java

So that's the correct path I edited my bashrc file added the following lines

export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/bin/java
export JAVA_HOME

I still get the same error when I run gradle -v

1
  • Where is java installed? How did you installed it? – Braiam Jun 15 '14 at 13:31
6

This sort of question was also answered on Stack Overflow. Turns out that there is an export in /usr/bin/gradle that probably shouldn't be there.

One solution is to comment out that export line. Another solution is to use a PPA that has a different/newer Gradle.

1
  • I tried creating a dynamic symbolic link in my .bash_profile (because I use Jenv on Mac) at ln -s /usr/lib/jvm/default-java $JAVA_HOME and it did not resolve the issue for me. Would rather not edit my Gradle distro executor, but i guess if I have to... – djangofan Apr 23 '16 at 19:30
3

You have incorrectly set your JAVA_HOME variable. It shouldn't be pointing to the jre but to the jdk.

Set your JAVA_HOME variable to /usr/lib/jvm/java-7-oracle.

1
  • Not working for me...I got the latest gradle and moreover my JAVA_HOME is /usr/lib/jvm/oracle_jdk8 – Ashu Jan 24 '16 at 21:18
1

This is the problem with the gradle which is appending /bin/java JAVACMD="$JAVA_HOME/bin/java" to your JAVA_HOME path in its scripts. so go to your gradle-3.3/bin location of your gradle scripts and edit the gradle file using gedit.

    if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."

this is the code snippet which is appending the java path hence results in an invalid path since you have already included /bin/java in your JAVA_HOME. so either change it here or remove the /bin/java from your JAVA_HOME path variable from the /etc/environment. I have removed the /bin/java from the JAVA_HOME path and it worked fine for me.

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.