Gradle home cannot be found on Mac

JavaBashMacosGradle

Java Problem Overview


I've installed gradle on MAC using terminal.

brew install gradle

Gradle has been installed successfully.

gradle -v

------------------------------------------------------------
Gradle 3.3
------------------------------------------------------------

Build time:   2017-01-03 15:31:04 UTC
Revision:     075893a3d0798c0c1f322899b41ceca82e4e134b

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_112 (Oracle Corporation 25.112-b16)
OS:           Mac OS X 10.12.3 x86_64

but I can not find gradle home.

echo $GRADLE_HOME
[empty result]

the first step to determine home directory is detect location of gradle instruction:

which gradle
/usr/local/bin/gradle

there is incomprehensible bash file.


Any ideas how to detect gradle home directory via terminal?

Java Solutions


Solution 1 - Java

You can use command:

brew info gradle

As the result you will have something like this:

gradle: stable 4.0.1
Build system based on the Groovy language
https://www.gradle.org/
/usr/local/Cellar/gradle/3.4 (181 files, 74.5MB) *
  Built from source on 2017-02-24 at 15:01:34
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Requirements
Required: java >= 1.7 ✔
==> Options
--with-all
	Installs Javadoc, examples, and source in addition to the binaries

Here, on the line 4 you can see the home path : /usr/local/Cellar/gradle/3.4

Solution 2 - Java

You can retrieve the path for GRADLE_HOME automatically using the following snippet in your .bashrc or .zshrc:

export GRADLE_HOME=$(brew info gradle | grep /usr/local/Cellar/gradle | awk '{print $1}')

This is handy when the path to Gradle's home changes, when Gradle is updated.

Solution 3 - Java

On Mojave (v10.14), Gradle v5.4, I had to append libexec after Gradle version for IntelliJ to work.

/usr/local/Cellar/gradle/5.4/libexec

Solution 4 - Java

I've gradle installed When using homebrew, below one failed with me, and kept telling undefined:

/usr/local/Cellar/gradle/<version>

The below symlink worked perfectly, and solved my issue:

/usr/local/opt/gradle/libexec

Solution 5 - Java

"brew info gradle" command not always give the installed path

br*ew info gradle
gradle: stable 5.6.3
Open-source build automation tool based on the Groovy and Kotlin DSL
https://www.gradle.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Requirements
Required: java >= 1.8 ✔
==> Analytics
install: 29,106 (30 days), 144,607 (90 days), 611,211 (365 days)
install_on_request: 28,237 (30 days), 137,584 (90 days), 577,691 (365 days)
build_error: 0 (30 days)*

Solution 6 - Java

On Mojave, Gradle v6.6, I appended libexec after Gradle version for IntelliJ to work.

/usr/local/Cellar/gradle/5.4/libexec

Solution 7 - Java

My point isn't enough for commenting on flic's answer in the previous post. If it happens to be in MacOS, the asterisk should be escaped as:

brew info gradle | sed -nE 's#^(/usr/local/Cellar/gradle/[^ ]+).+\*#\1#p'

or there will be sed: 1: "s#^(/usr/local/Cellar/g ...: RE error: repetition-operator operand invalid" error reported.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSergiiView Question on Stackoverflow
Solution 1 - JavadveloppView Answer on Stackoverflow
Solution 2 - JavajokosoView Answer on Stackoverflow
Solution 3 - JavaMoazzem HossenView Answer on Stackoverflow
Solution 4 - JavaHasan A YousefView Answer on Stackoverflow
Solution 5 - JavaSNLView Answer on Stackoverflow
Solution 6 - JavaSunilView Answer on Stackoverflow
Solution 7 - JavaChinbat G.View Answer on Stackoverflow