// Copyright (C) 2024 Gradle, Inc.
//
// Licensed under the Creative Commons Attribution-Noncommercial-ShareAlike 4.0 International License.;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

[[installation]]
= Installing Gradle
:keywords: install

[[gs:installation]]
== Gradle Installation

If all you want to do is run an existing Gradle project, then you don't need to install Gradle if the build uses the <<gradle_wrapper#gradle_wrapper_reference,Gradle Wrapper>>.
This is identifiable by the presence of the `gradlew` or `gradlew.bat` files in the root of the project:

[listing,subs=+macros]
----
.   // <1>
├── gradle
│   └── wrapper // <2>
├── gradlew         // <3>
├── gradlew.bat     // <3>
└── ⋮
----
<1> Project root directory.
<2> <<gradle_wrapper.adoc#gradle_wrapper_reference,Gradle Wrapper>>.
<3> Scripts for executing Gradle builds.

If the `gradlew` or `gradlew.bat` files are already present in your project, *you do not need to install Gradle*.
But you need to make sure your system <<installation#sec:prerequisites,satisfies Gradle's prerequisites>>.

You can follow the steps in the <<upgrading_version_8.adoc#upgrading_version_8,Upgrading Gradle section>> if you want to update the Gradle version for your project.
Please use the <<gradle_wrapper.adoc#sec:upgrading_wrapper,Gradle Wrapper>> to upgrade Gradle.

Android Studio comes with a working installation of Gradle, so you *don't need to install Gradle separately when only working within that IDE*.

If you do not meet the criteria above and decide to install Gradle on your machine, first check if Gradle is already installed by running `gradle -v` in your terminal.
If the command does not return anything, then Gradle is not installed, and you can follow the instructions below.

You can install Gradle Build Tool on Linux, macOS, or Windows.
The installation can be done manually or using a package manager like https://sdkman.io/[SDKMAN!] or https://brew.sh/[Homebrew].

You can find all Gradle releases and their checksums on the link:{website}/releases[releases page].

[[sec:prerequisites]]
== Prerequisites
Gradle runs on all major operating systems. It requires link:{jdkDownloadUrl}[Java Development Kit] (JDK) version {minJdkVersion} or higher to run. You can check the <<compatibility.adoc#compatibility,compatibility matrix>> for more information.

To check, run `java -version`:

----
❯ java -version
openjdk version "17.0.6" 2023-01-17
OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10)
OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode)
----

Gradle uses the JDK it finds in your path, the JDK used by your IDE, or the <<gradle_daemon#sec:configuring_daemon_jvm,JDK specified in your project>>.

In this example, the $PATH points to JDK17:

----
❯ echo $PATH
/opt/homebrew/opt/openjdk@17/bin
----

You can also set the `JAVA_HOME` environment variable to point to a specific JDK installation directory.
This is especially useful when multiple JDKs are installed:

----
❯ echo %JAVA_HOME%
C:\Program Files\Java\jdk17.0_6
----

----
❯ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
----

Gradle supports link:https://kotlinlang.org/[Kotlin] and link:https://groovy-lang.org/[Groovy] as the main build languages.
Gradle ships with its own Kotlin and Groovy libraries, therefore they do not need to be installed.
Existing installations are ignored by Gradle.

<<compatibility.adoc#compatibility, See the full compatibility notes for Java, Groovy, Kotlin, and Android.>>

== Linux installation

.Installing with a package manager
[%collapsible]
====

link:http://sdkman.io[SDKMAN!] is a tool for managing parallel versions of multiple Software Development Kits on most Unix-like systems (macOS, Linux, Cygwin, Solaris and FreeBSD).
Gradle is deployed and maintained by SDKMAN!:

----
❯ sdk install gradle
----

Other package managers are available, but the version of Gradle distributed by them is not controlled by Gradle, Inc.
Linux package managers may distribute a modified version of Gradle that is incompatible or incomplete when compared to the official version.
====

.Installing manually
[%collapsible]
====

**Step 1 - link:{website}/releases[Download] the latest Gradle distribution**

The distribution ZIP file comes in two flavors:

- Binary-only (bin)
- Complete (all) with docs and sources

We recommend downloading the bin file; it is a smaller file that is quick to download (and the latest documentation is available online).

**Step 2 - Unpack the distribution**

Unzip the distribution zip file in the directory of your choosing, e.g.:

[subs="attributes"]
----
❯ mkdir /opt/gradle
❯ unzip -d /opt/gradle gradle-{gradleVersion}-bin.zip
❯ ls /opt/gradle/gradle-{gradleVersion}
LICENSE  NOTICE  bin  README  init.d  lib  media
----

[[sec:linux_macos_users_2]]

**Step 3 - Configure your system environment**

To install Gradle, the path to the unpacked files needs to be in your Path.
Configure your `PATH` environment variable to include the `bin` directory of the unzipped distribution, e.g.:

[subs="attributes"]
----
❯ export PATH=$PATH:/opt/gradle/gradle-{gradleVersion}/bin
----

Alternatively, you could also add the environment variable `GRADLE_HOME` and point this to the unzipped distribution.
Instead of adding a specific version of Gradle to your `PATH`, you can add `$GRADLE_HOME/bin` to your `PATH`.
When upgrading to a different version of Gradle, simply change the `GRADLE_HOME` environment variable.

[subs="attributes"]
----
export GRADLE_HOME=/opt/gradle/gradle-{gradleVersion}
export PATH=${GRADLE_HOME}/bin:${PATH}
----
====

== macOS installation

.Installing with a package manager
[%collapsible]
====

link:http://sdkman.io[SDKMAN!] is a tool for managing parallel versions of multiple Software Development Kits on most Unix-like systems (macOS, Linux, Cygwin, Solaris and FreeBSD).
Gradle is deployed and maintained by SDKMAN!:

----
❯ sdk install gradle
----

Using link:http://brew.sh[Homebrew]:

----
❯ brew install gradle
----

Using link:https://www.macports.org[MacPorts]:

----
❯ sudo port install gradle
----

Other package managers are available, but the version of Gradle distributed by them is not controlled by Gradle, Inc.
====

.Installing manually
[%collapsible]
====

**Step 1 - link:{website}/releases[Download] the latest Gradle distribution**

The distribution ZIP file comes in two flavors:

- Binary-only (bin)
- Complete (all) with docs and sources

We recommend downloading the bin file; it is a smaller file that is quick to download (and the latest documentation is available online).

**Step 2 - Unpack the distribution**

Unzip the distribution zip file in the directory of your choosing, e.g.:

[subs="attributes"]
----
❯ mkdir /usr/local/gradle
❯ unzip gradle-{gradleVersion}-bin.zip -d /usr/local/gradle
❯ ls /usr/local/gradle/gradle-{gradleVersion}
LICENSE	NOTICE	README	bin	init.d	lib
----

**Step 3 - Configure your system environment**

To install Gradle, the path to the unpacked files needs to be in your Path.
Configure your `PATH` environment variable to include the `bin` directory of the unzipped distribution, e.g.:

[subs="attributes"]
----
❯ export PATH=$PATH:/usr/local/gradle/gradle-{gradleVersion}/bin
----

Alternatively, you could also add the environment variable `GRADLE_HOME` and point this to the unzipped distribution.
Instead of adding a specific version of Gradle to your `PATH`, you can add `$GRADLE_HOME/bin` to your `PATH`.
When upgrading to a different version of Gradle, simply change the `GRADLE_HOME` environment variable.

It's a good idea to edit `.bash_profile` in your home directory to add `GRADLE_HOME` variable:

[subs="attributes"]
----
export GRADLE_HOME=/usr/local/gradle/gradle-{gradleVersion}
export PATH=$GRADLE_HOME/bin:$PATH
----
====

== Windows installation

.Installing manually
[%collapsible]
====

**Step 1 - link:{website}/releases[Download] the latest Gradle distribution**

The distribution ZIP file comes in two flavors:

- Binary-only (bin)
- Complete (all) with docs and sources

We recommend downloading the bin file.

**Step 2 - Unpack the distribution**

Create a new directory `C:\Gradle` with **File Explorer**.

Open a second **File Explorer** window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP archive to expose the content.
Drag the content folder `gradle-{gradleVersion}` to your newly created `C:\Gradle` folder.

Alternatively, you can unpack the Gradle distribution ZIP into `C:\Gradle` using the archiver tool of your choice.

**Step 3 - Configure your system environment**

To install Gradle, the path to the unpacked files needs to be in your Path.

In **File Explorer** right-click on the `This PC` (or `Computer`) icon, then click `Properties` -> `Advanced System Settings` -> `Environmental Variables`.

Under `System Variables` select `Path`, then click `Edit`.
Add an entry for `C:\Gradle\gradle-{gradleVersion}\bin`.
Click `OK` to save.

Alternatively, you can add the environment variable `GRADLE_HOME` and point this to the unzipped distribution.
Instead of adding a specific version of Gradle to your `Path`, you can add `__%GRADLE_HOME%__\bin` to your `Path`.
When upgrading to a different version of Gradle, just change the `GRADLE_HOME` environment variable.
====

[[sec:running_and_testing_your_installation]]
== Verify the installation

Open a console (or a Windows command prompt) and run `gradle -v` to run gradle and display the version, e.g.:

[subs="attributes"]
----
❯ gradle -v

------------------------------------------------------------
Gradle {gradleVersion}
------------------------------------------------------------

Build time:    2025-05-13 06:56:13 UTC
Revision:      3c890746756262d3778e12eaa5155d661d7cbdf2

Kotlin:        2.1.21
Groovy:        4.0.27
Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM:  22.0.1 (Oracle Corporation 22.0.1+8-16)
Daemon JVM:    Compatible with Java 17, any vendor, nativeImageCapable=false (from gradle/gradle-daemon-jvm.properties)
OS:            Mac OS X 15.5 aarch64

----

You can verify the integrity of the Gradle distribution by downloading the SHA-256 file (available from the link:{website}/releases[releases page]) and following these <<gradle_wrapper.adoc#sec:verification,verification instructions>>.
