Install Gradle on Debian 10/9

|
Last Updated:
|
|

In this guide, we are going to learn how to install Gradle on Debian 10/9. Gradle is an open-source build automation tool for building (but not limited) Java-based projects. Gradle build scripts are written using a Groovy or Kotlin domain-specific language (DSL) instead of the XML form commonly used by Apache Maven for declaring the project configuration.

Installing Gradle on Debian 10/9

There are two ways in which Gradle can be installed; Automatically via the package manager and manually using Gradle binary. This guide discusses both ways.

Prerequisites

Gradle runs on the JVM and thus as a prerequisite, you have to install OpenJDK or JRE 8 or later. Hence, update you system and install JDK.

Run system update

apt update
apt upgrade

Install Java on Debian 10/9

We have covered the installation of various versions of Java in our previous guides. See the links below.

Install Oracle Java 12 on Debian 10

How to Manually Install Oracle Java 12 on Debian 10/9/Ubuntu 18.04

Install Oracle Java 12 on Ubuntu 18.04/Debian 10/9

Install Java 11 on Debian 10/9/Ubuntu 18.04

Installing Gradle on Debian Package Manager

To install Gradle via package manager, you need to first install SDKMAN!, a tool for managing parallel versions of multiple Software Development Kits on most Unix-like systems.

Install SDKMAN! on Debian 10/9

To install SDKMAN!, run the commands below;

apt install zip curl
curl -s "https://get.sdkman.io" | bash

SDKMAN! is installed on your home directory. Hence, once the installation is done, run the command below source the SDKMAN! init script.

source "$HOME/.sdkman/bin/sdkman-init.sh"

To verify SDKMAN! installation;

sdk version
...
SDKMAN 5.12.1

Install Gradle on Debian

You can now install Gradle using SDKMAN! by running the command;

sdk install gradle

You can also specify the version to install e.g;

sdk install gradle VERSION

Replace VERSION with the version number of Gradle to install. To list the available versions, run the command below;

sdk list gradle

Once the installation of Gradle completes, the installed version is displayed. You can as well check the version as shown below;

gradle -v

Welcome to Gradle 7.1.1!

Here are the highlights of this release:
 - Faster incremental Java compilation
 - Easier source set configuration in the Kotlin DSL

For more details see https://docs.gradle.org/7.1.1/release-notes.html


------------------------------------------------------------
Gradle 7.1.1
------------------------------------------------------------

Build time:   2021-07-02 12:16:43 UTC
Revision:     774525a055494e0ece39f522ac7ad17498ce032c

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (Debian 11.0.11+9-post-Debian-1deb10u1)
OS:           Linux 4.19.0-17-amd64 amd64

Installing Gradle Manually via the Gradle Binary

Download Gradle Binary

To manually install Gradle using the binary, navigate to Grade releases page and grab the latest release binary. As of this writing, it is version 7.1.1. You can simply download the binary with wget command as follows.

wget https://downloads.gradle.org/distributions/gradle-7.1.1-bin.zip

Extract the Binary

Once the installation is done, extract the binary to install directory. This demo uses /opt/ directory.

unzip gradle-7.1.1-bin.zip -d /opt/

The Gradle 7.1.1 contents are extracted to /opt/gradle-7.1.1.

ls /opt/gradle-7.1.1
bin  init.d  lib  LICENSE  NOTICE  README

Configure Gradle Environment Variables

Next, you need to create global Gradle home environment variable, GRADLE_HOME. You also need to add the Gradle bin directory to your PATH. These configs can be defined under the /etc/profile.d/ as a script.

cat > /etc/profile.d/gradle.sh << 'EOL'
export GRADLE_HOME=/opt/gradle-7.1.1
export PATH=${GRADLE_HOME}/bin:${PATH}
EOL

Next, add the execute permissions to the script.

chmod +x /etc/profile.d/gradle.sh

Once that is done, source the script to load the Gradle environment variables set.

source /etc/profile.d/gradle.sh

Next, verify the version of Gradle installed.

gradle -v

------------------------------------------------------------
Gradle 7.1.1
------------------------------------------------------------

Build time:   2021-07-02 12:16:43 UTC
Revision:     774525a055494e0ece39f522ac7ad17498ce032c

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (Debian 11.0.11+9-post-Debian-1deb10u1)
OS:           Linux 4.19.0-17-amd64 amd64

Well, you have successfully installed Gradle and that is all on how to install Gradle on Debian.

Reference:

Getting started with Gradle

Other Tutorials

Install Gradle on Rocky Linux 8

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Jay Decrame
Linux Certified Engineer, Technology and Linux/Unix enthusiast.

Leave a Comment