Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle does not recognize the JAVA_HOME I have set

I have set my JAVA_HOME to /usr/lib/jvm/java-7-oracle, which contains a valid JVM, but gradle insists on using /usr/lib/jvm/default-java and complains about JAVA_HOME:

$ echo $JAVA_HOME 
/usr/lib/jvm/java-7-oracle
$ ls $JAVA_HOME
bin  COPYRIGHT  db  include  jre  lib  LICENSE  man  README.html  release  src.zip  THIRDPARTYLICENSEREADME-JAVAFX.txt  THIRDPARTYLICENSEREADME.txt
$ gradle assemble

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java

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

How can I fix this and have gradle use my valid JAVA_HOME?

Note: My JAVA_HOME is set by ~/.bashrc using export JAVA_HOME="/usr/lib/jvm/java-7-oracle"

like image 417
Nicolas Raoul Avatar asked Nov 12 '14 08:11

Nicolas Raoul


People also ask

Why JAVA_HOME is not working?

Verify JAVA_HOME Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly. Please make sure you're using the correct Java installation folder, or repeat the steps above.

How do you fix error JAVA_HOME is not set and no Java command could be found in your path?

Download Liberica JDK and on installation it will automatically set JAVA_HOME environment variable. Now you just go to Android Studio -> Project Structure -> SDK -> Point all jdk path to liberica jdk installation directory and apply. You are done. Just restart android studio and gradle command will work.

How do you fix please set the JAVA_HOME variable in your environment to match the location of your Java installation?

Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.

Does JAVA_HOME point to JRE or JDK?

The JAVA_HOME environment variable points to the file system location where the JDK or JRE was installed. This variable should be configured on all OS's that have a Java installation, including Windows, Ubuntu, Linux, Mac and Android.


2 Answers

it is quite common issue. Just go to your gradle home directory and bin, for example:

/home/user/gradle-2.0/bin

and there you should have gradle script, I am on a Windows machine now so I have gradle.bat, probably you will have gradle.sh or something like this. In that file, find the line:

set JAVA_HOME=%JAVA_HOME:"=%

or as I can see you are on linux so there will be "export" and change it to your java home directory for example:

export JAVA_HOME=/usr/lib/jvm/java-7-oracle
like image 151
SuperAndrew Avatar answered Oct 19 '22 23:10

SuperAndrew


If on windows, also make changes to JAVA_EXE and add your path

    set JAVA_EXE=C:\yourpath\bin\java.exe
like image 37
Armaan Dhir Avatar answered Oct 20 '22 01:10

Armaan Dhir